subset an image into regular grids and calculate mean value of each grid object

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

subset an image into regular grids and calculate mean value of each grid object

Keira Wilson
Dear all,
I want to divide a tiff image (500 by 500 pixels) into regular rectangular
grids of 50 by 50 pixels (100 grid objects in total), and to calculate mean
RGB value of each grid object using python script . I also want to overlay
the grid lines and grid objects ID (1 to 100) in that image. I would learn
easily if someone could write a very simple code for this purpose.
I appreciate for your time.
Keira

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: subset an image into regular grids and calculate mean value of each grid object

George Patterson-3
Hi Keira,
Something like this might get you started.
Best,
George


print("\\Clear");
Overlay.remove;
xGridSize=50;
yGridSize=50;

width=getWidth();
height=getHeight();
GridNum=1;

for(y=0;y<=height-yGridSize;y+=yGridSize){
for(x=0;x<=width-xGridSize;x+=xGridSize){
makeRectangle(x,y,xGridSize,yGridSize);
getStatistics(Area, Mean);
print(Mean);
Overlay.drawRect(x,y,xGridSize,yGridSize);
Overlay.drawString(GridNum,x,y+15);
GridNum++;
Overlay.show;
}
}

On May 22, 2013, at 1:38 AM, Keira Wilson wrote:

> Dear all,
> I want to divide a tiff image (500 by 500 pixels) into regular rectangular
> grids of 50 by 50 pixels (100 grid objects in total), and to calculate mean
> RGB value of each grid object using python script . I also want to overlay
> the grid lines and grid objects ID (1 to 100) in that image. I would learn
> easily if someone could write a very simple code for this purpose.
> I appreciate for your time.
> Keira
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

George H. Patterson
Building 13 3E33
13 South Drive
Biophotonics Section
National Institute of Biomedical Imaging and Bioengineering
National Institutes of Health
Bethesda, MD 20892
Office: 301-443-0241
Fax: 301-496-6608
[hidden email]


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: subset an image into regular grids and calculate mean value of each grid object

Keira Wilson
Hi George,
Thank you for your nice code, it worked!
However, how can I make it to work for 100 grid objects?
Thank you so much in advance.
Keira



On Thu, May 23, 2013 at 12:21 AM, George Patterson <[hidden email]>wrote:

> Hi Keira,
> Something like this might get you started.
> Best,
> George
>
>
> print("\\Clear");
> Overlay.remove;
> xGridSize=50;
> yGridSize=50;
>
> width=getWidth();
> height=getHeight();
> GridNum=1;
>
> for(y=0;y<=height-yGridSize;y+=yGridSize){
> for(x=0;x<=width-xGridSize;x+=xGridSize){
> makeRectangle(x,y,xGridSize,yGridSize);
> getStatistics(Area, Mean);
> print(Mean);
> Overlay.drawRect(x,y,xGridSize,yGridSize);
> Overlay.drawString(GridNum,x,y+15);
> GridNum++;
> Overlay.show;
> }
> }
>
> On May 22, 2013, at 1:38 AM, Keira Wilson wrote:
>
> > Dear all,
> > I want to divide a tiff image (500 by 500 pixels) into regular
> rectangular
> > grids of 50 by 50 pixels (100 grid objects in total), and to calculate
> mean
> > RGB value of each grid object using python script . I also want to
> overlay
> > the grid lines and grid objects ID (1 to 100) in that image. I would
> learn
> > easily if someone could write a very simple code for this purpose.
> > I appreciate for your time.
> > Keira
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> George H. Patterson
> Building 13 3E33
> 13 South Drive
> Biophotonics Section
> National Institute of Biomedical Imaging and Bioengineering
> National Institutes of Health
> Bethesda, MD 20892
> Office: 301-443-0241
> Fax: 301-496-6608
> [hidden email]
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: subset an image into regular grids and calculate mean value of each grid object

Keira Wilson
Hi George,
Thank you so much for your nice code, it also worked for 100 objects.
Thank you very much.
Keira

On Thu, May 23, 2013 at 12:41 AM, Keira Wilson <[hidden email]> wrote:

> Hi George,
> Thank you for your nice code, it worked!
>  However, how can I make it to work for 100 grid objects?
> Thank you so much in advance.
>  Keira
>
>
>
> On Thu, May 23, 2013 at 12:21 AM, George Patterson <[hidden email]>wrote:
>
>> Hi Keira,
>> Something like this might get you started.
>> Best,
>> George
>>
>>
>> print("\\Clear");
>> Overlay.remove;
>> xGridSize=50;
>> yGridSize=50;
>>
>> width=getWidth();
>> height=getHeight();
>> GridNum=1;
>>
>> for(y=0;y<=height-yGridSize;y+=yGridSize){
>> for(x=0;x<=width-xGridSize;x+=xGridSize){
>> makeRectangle(x,y,xGridSize,yGridSize);
>> getStatistics(Area, Mean);
>> print(Mean);
>> Overlay.drawRect(x,y,xGridSize,yGridSize);
>> Overlay.drawString(GridNum,x,y+15);
>> GridNum++;
>> Overlay.show;
>> }
>> }
>>
>> On May 22, 2013, at 1:38 AM, Keira Wilson wrote:
>>
>> > Dear all,
>> > I want to divide a tiff image (500 by 500 pixels) into regular
>> rectangular
>> > grids of 50 by 50 pixels (100 grid objects in total), and to calculate
>> mean
>> > RGB value of each grid object using python script . I also want to
>> overlay
>> > the grid lines and grid objects ID (1 to 100) in that image. I would
>> learn
>> > easily if someone could write a very simple code for this purpose.
>> > I appreciate for your time.
>> > Keira
>> >
>> > --
>> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>> George H. Patterson
>> Building 13 3E33
>> 13 South Drive
>> Biophotonics Section
>> National Institute of Biomedical Imaging and Bioengineering
>> National Institutes of Health
>> Bethesda, MD 20892
>> Office: 301-443-0241
>> Fax: 301-496-6608
>> [hidden email]
>>
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html