import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.imageio.ImageIO;
import ij.ImagePlus;
public class GetPixelCoordinates {
//int y, x, tofind, col;
/**
* @param args the command line arguments
* @throws IOException
*/
public static void main(String args[]) throws IOException {
try {
//read image file
//File file1 = new File("E:\\M+R25Adj-1.bmp");
//BufferedImage image1 = ImageIO.read(file1);
ImagePlus image1 = new ImagePlus("E:\\M+R25Adj-1.tiff");
//write file
FileWriter fstream = new FileWriter("E:\\pixellog1.txt");
BufferedWriter out = new BufferedWriter(fstream);
//find cyan pixels
for (int y = 0; y < image1.getHeight(); y++) {
for (int x = 0; x < image1.getWidth(); x++) {
int c = image1.getPixel(x,y);
Color color = new Color(c);
if (color.getRed() < 30 && color.getGreen() >= 225 && color.getBlue() >= 225) {
out.write("CyanPixel found at=" + x + "," + y);
out.newLine();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
This post has been edited by Atli: 06 February 2012 - 10:52 PM
Reason for edit:: Please use [code] tags when posting code.

New Topic/Question
Reply



MultiQuote




|