Pixel by pixel intensity in a circular ROI

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

Pixel by pixel intensity in a circular ROI

Runa Hamid
Dear image J users,

I need to use a macro for a circular ROI to obtain pixel by pixel
intensities in that ROI (ROI have 497 total pixels). I got a below appended
macro for a rectangular ROI from one of the image J users earlier. I would
be greatly thankful if any one can help me to convert this macro to obtain
values for circular ROI.  I do not know programming at all.


w= getWidth() ; h = getHeight();
getSelectionBounds(xmin, ymin, selwidth, selheight);
run("Create Mask");
m=newArray(w*h);
for(x=0;x<w;x++){
        for(y=0;y<h;y++){
                m[y*w+x]=getPixel(x,y);
        }
}
close(); //close mask
for(x=xmin;(x<=xmin+selwidth);x++){
        for(y=ymin;(y<=ymin+selheight);y++){
                if (m[y*w+x]!=0) print (x,y,getPixel(x,y));
        }
}

Thanks In advance
Runa
Reply | Threaded
Open this post in threaded view
|

Re: Pixel by pixel intensity in a circular ROI

Wayne Rasband
On May 28, 2009, at 7:53 AM, Runa Hamid wrote:

> Dear image J users,
>
> I need to use a macro for a circular ROI to obtain pixel by pixel
> intensities in that ROI (ROI have 497 total pixels). I got a below
> appended
> macro for a rectangular ROI from one of the image J users earlier. I
> would
> be greatly thankful if any one can help me to convert this macro to
> obtain
> values for circular ROI.  I do not know programming at all.
>
>
> w= getWidth() ; h = getHeight();
> getSelectionBounds(xmin, ymin, selwidth, selheight);
> run("Create Mask");
> m=newArray(w*h);
> for(x=0;x<w;x++){
>         for(y=0;y<h;y++){
>                 m[y*w+x]=getPixel(x,y);
>         }
> }
> close(); //close mask
> for(x=xmin;(x<=xmin+selwidth);x++){
>         for(y=ymin;(y<=ymin+selheight);y++){
>                 if (m[y*w+x]!=0) print (x,y,getPixel(x,y));
>         }
> }

The code above does obtain the values of pixels inside a
non-rectangular selection. You can see this by modifying the code so
that it draws each pixel. You can avoid having the mask image displayed
by running the macro in batch mode.

   setBatchMode(true);
   w= getWidth(); h=getHeight();
   getSelectionBounds(xmin, ymin, selwidth, selheight);
   run("Create Mask");
   m=newArray(w*h);
   for (x=0; x<w; x++) {
      for(y=0; y<h; y++) {
         m[y*w+x]=getPixel(x,y);
      }
   }
   close(); //close mask
   for(x=xmin; x<=xmin+selwidth; x++) {
      for(y=ymin; y<=ymin+selheight; y++) {
         if (m[y*w+x]!=0) {
            print (x,y,getPixel(x,y));
            drawRect(x,y,1,1);
         }
      }
   }

-wayne