Another newbie question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Another newbie question

bateman
Hello Again,

I'm a little confused. I plan to make a program that searches the pixel values within an ROI and invert the pixels that are half the value of the central pixel in the Roi. Here is my code:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.filter.*;

public class Light_radn implements PlugInFilter {
        ImagePlus imp;
               
        public int setup(String arg, ImagePlus imp) {
                this.imp = imp;
                return DOES_ALL;
        }

        public void run(ImageProcessor ip) {

        Rectangle r = ip.getRoi();
        ip.setRoi(r);
       
        int h = ip.getHeight();
        int w = ip.getWidth();
        int max = ip.getPixel(w/2,h/2);
        int halfmax = max/2;

        for(int i =0; i<w; i++){
                for(int u =0; u<h; u++){
                       
                        int pixval = ip.getPixel(i,u);
                       
                        if (pixval ==halfmax)
                        {
                                ip .putPixel(i,u,  255-pixval);
                        }
                }
        }

        }

}

It may be my understanding that is at fault.

If I draw a rectangular ROI and make a code with the method ip.invert() only the pixels within the ROI are affected. However if I draw a rectangle and run the code above pixels are affected that are outside the ROI.

So why does imagej accept an ROI when performing ip.invert(), and not apply the code above to those pixels within the ROI?

Thank you for your time

Bateman
Reply | Threaded
Open this post in threaded view
|

Re: Another newbie question

bateman
I think I understand.

I think that it is the way i'm indexing the pixels during the for loops.

Thanks anyway

Bateman