Re: Problem with ImagePlus getPixel method
Posted by
Mathias Zech on
Mar 19, 2009; 9:38pm
URL: http://imagej.273.s1.nabble.com/Problem-with-ImagePlus-getPixel-method-tp3693248p3693250.html
THank you, I forgot to mention that it was an ImagePlus instance.
Calling updateImage() solves the problem!
Thanks a lot!
Mathias
Jeffrey B. Woodward wrote:
> I assume that in the code below that imgBinary is an instanceof
> ImagePlus. If so, try calling imgBinary.updateImage() after you
> updated the corresponding BinaryProcessor and before you call
> imgBinary.getPixel().
>
> -Woody
>
>
> Mathias Zech wrote:
>> Hello,
>>
>> I have just found an interesting problem with the getPixel method of
>> ImagePlus. I will illustrate it with some example code. It is
>> important to know, that I created the image via a BinaryProcessor and
>> did not display/show it before reaching this code:
>>
>> for(Point point : points) {
>> int[] values = imgBinary.getPixel(point.x, point.y);
>> System.out.println("VAL: " + values[0] + "/" + values[1] +
>> "/" + values[2] + "/" + values[3]);
>> if(values[0] != 0) { //color black == 0 == outside
>> removePoints.add(point);
>> } //if
>> } //for
>>
>> When I run this, the content of values is always 0, the output looks
>> something like this:
>>
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>>
>>
>> When I display the image beforehand, however, the code works as
>> expected:
>>
>> imgBinary.show();
>> imgBinary.hide();
>> for(Point point : points) {
>> int[] values = imgBinary.getPixel(point.x, point.y);
>> System.out.println("VAL: " + values[0] + "/" + values[1] +
>> "/" + values[2] + "/" + values[3]);
>> if(values[0] != 0) { //color black == 0 == outside
>> removePoints.add(point);
>> } //if
>> } //for
>>
>> The output then looks like this:
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>> VAL: 255/0/0/0
>> VAL: 0/0/0/0
>> VAL: 0/0/0/0
>>
>> The second case it what I expect but why do I need to call show()
>> before I can use getPixel? I do not want to do this at that moment
>> because this image is just a temporary helper image which I do save
>> if debugging is enabled but usually just throw away after this
>> section of code completes.
>>
>> I hope someone has an idea, thanks in advance!
>> Mathias
>>
>>