4 Replies - 263 Views - Last Post: 07 February 2012 - 07:01 PM Rate Topic: -----

Topic Sponsor:

#1 lostsoul28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

scanning pixels of .tiff image using imageJ library

Posted 06 February 2012 - 10:45 PM

im using the imageJ library to read a .tiff image file. But when im trying to read the pixels of image1 in variable c, i get an error saying "incompatible types: required int, found int[]. im quiet new to java, so can somebody tell me how to get around this problem. The code is otherwise working fine with other image formats.


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.


Is This A Good Question/Topic? 0
  • +

Replies To: scanning pixels of .tiff image using imageJ library

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1812
  • View blog
  • Posts: 4,891
  • Joined: 27-December 05

Re: scanning pixels of .tiff image using imageJ library

Posted 07 February 2012 - 12:12 AM

According to the ImagePlus API, getPixel returns an array of 4 ints, but you're trying to assign it to an int.

Change line 33 to
int[] c = image1.getPixel(x,y);


But then since c will now be an array you'll have to change the next line accordingly. Consult the API for more details about the array that will be returned.
Was This Post Helpful? 1
  • +
  • -

#3 lostsoul28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

Re: scanning pixels of .tiff image using imageJ library

Posted 07 February 2012 - 12:28 AM

View Postr.stiltskin, on 07 February 2012 - 12:12 AM, said:

According to the ImagePlus API, getPixel returns an array of 4 ints, but you're trying to assign it to an int.

Change line 33 to
int[] c = image1.getPixel(x,y);


But then since c will now be an array you'll have to change the next line accordingly. Consult the API for more details about the array that will be returned.



umm yeah i got that but how do i get the color object to take int[] as an argument?? confused here :(
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 719
  • View blog
  • Posts: 1,692
  • Joined: 05-May 05

Re: scanning pixels of .tiff image using imageJ library

Posted 07 February 2012 - 04:27 AM

Quote

Returns the pixel value at (x,y) as a 4 element array. Grayscale values are retuned in the first element. RGB values are returned in the first 3 elements. For indexed color images, the RGB values are returned in the first 3 three elements and the index (0-255) is returned in the last.
~ ImagePlus.getPixel docs

The docs sound nonsensical to me, but I'd try this:

int[] rgbComponents = image1.getPixel(x,y);
int r = rgbComponents[0];
int g = rgbComponents[1];
int b = rgbComponents[2];
Color c = new Color( r, g, b );


Was This Post Helpful? 1
  • +
  • -

#5 lostsoul28  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 05-February 12

Re: scanning pixels of .tiff image using imageJ library

Posted 07 February 2012 - 07:01 PM

View Postblackcompe, on 07 February 2012 - 04:27 AM, said:

Quote

Returns the pixel value at (x,y) as a 4 element array. Grayscale values are retuned in the first element. RGB values are returned in the first 3 elements. For indexed color images, the RGB values are returned in the first 3 three elements and the index (0-255) is returned in the last.
~ ImagePlus.getPixel docs

The docs sound nonsensical to me, but I'd try this:

int[] rgbComponents = image1.getPixel(x,y);
int r = rgbComponents[0];
int g = rgbComponents[1];
int b = rgbComponents[2];
Color c = new Color( r, g, b );




Thanks a lot. This worked great :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1