http://imagej.273.s1.nabble.com/Possible-to-access-pixels-without-creating-java-awt-image-tp3696328p3696329.html
Ah, great! I'll take a look at ImageReader. Also off-list, Johannes
> I _think_ that the java.awt.headless property is respected on MacOSX.
A quick check on my laptop confirmed that this works. Unless some
other obstacle comes up, this is likely a better solution. It might be
account would like to. :)
Thanks to Johannes, Wayne, and Alberto for your help.
>
> On May 6, 2008, at 8:15 AM,
[hidden email] wrote:
>
>> Hi Wayne,
>>
>> Thanks for the reply.
>>
>>> public ColorProcessor(int width, int height, int[] pixels) {
>> But that presupposes that I have the pixels. How do I get the
>> pixels without creating an instance java.awt.Image?
>
> The ij.io.ImageReader class returns pixel arrays.
>
>> I'm trying to use the ImageJ API to build a command-line
>> application. The problem that I'm running into is that core ImageJ
>> classes (like ImagePlus, ImageProcessor, ImageStack) instantiate
>> java.awt components (like ColorModel and Image). These cause my app
>> to create a GUI, even if they aren't visible, and even if I use
>> headless ImageJA. Creating a GUI generates a window server error on
>> the Mac cluster I'm using.
>
> One way to avoid window server errors is to use Xvfb (X virtual framebuffer).
>
> -wayne
>
>> So I've been hacking up custom versions of the above classes,
>> trying to strip out calls to java.awt classes, but I've reached a
>> point where I have to instantiate a ColorProcessor. In order to
>> make this work, I need to get rid of calls to
>> ImageProcessor:getImage(). In order to do that, I need some
>> alternative method to read in the pixels. java.awt.Image does it,
>> so I assume it's possible. The question is "How?" (and the
>> follow-up question is "How much code do I really want to re-write?").
>>
>> So I'm looking for suggestions to either question.
>>
>> Thanks,
>> Brian
>>
>>
>> Quoting Rasband Wayne:
>>
>>>> Is it possible to create an ImageProcessor (one that accesses the
>>>> pixels in a given tif file) without creating an instance of
>>>> java.awt.Image?
>>>>
>>>>
>>>> public ColorProcessor(Image img) {
>>>> width = img.getWidth(null);
>>>> height = img.getHeight(null);
>>>> pixels = new int[width * height];
>>>> PixelGrabber pg = new PixelGrabber(img, 0, 0, width, height,
>>>> pixels, 0, width);
>>>> try {
>>>> pg.grabPixels();
>>>> } catch (InterruptedException e){};
>>>> createColorModel();
>>>> fgColor = 0xff000000; //black
>>>> resetRoi();
>>>> }
>>>>
>>>> Thanks,
>>>> Brian
>>>
>>> Brian,
>>>
>>> You can use this constructor
>>>
>>> /**Creates a ColorProcessor from a pixel array. */
>>> public ColorProcessor(int width, int height, int[] pixels) {
>>> if (pixels!=null && width*height!=pixels.length)
>>> throw new IllegalArgumentException(WRONG_LENGTH);
>>> this.width = width;
>>> this.height = height;
>>> createColorModel();
>>> fgColor = 0xff000000; //black
>>> resetRoi();
>>> this.pixels = pixels;
>>> }
>>>
>>> to create an ImageProcessor from an array of RGB pixels. What are you
>>> trying to accomplish?
>>>
>>> -wayne
>>
>>
>>