Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MeanIntensity

Subject: MeanIntensity

From: Aikerim

Date: 20 Jul, 2011 19:04:09

Message: 1 of 16

Hello,
Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
I got these errors:
??? Error using ==> regionprops>ParseInputs at 1112
Size of I doesn't match size information found in the first input argument.

Error in ==> regionprops at 154
[I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
please help!

Subject: MeanIntensity

From: Jeff

Date: 20 Jul, 2011 19:43:09

Message: 2 of 16

"Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> Hello,
> Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> I got these errors:
> ??? Error using ==> regionprops>ParseInputs at 1112
> Size of I doesn't match size information found in the first input argument.
>
> Error in ==> regionprops at 154
> [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> please help!

To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).

An example:
stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');

Subject: MeanIntensity

From: Aikerim

Date: 20 Jul, 2011 20:04:10

Message: 3 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > Hello,
> > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > I got these errors:
> > ??? Error using ==> regionprops>ParseInputs at 1112
> > Size of I doesn't match size information found in the first input argument.
> >
> > Error in ==> regionprops at 154
> > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > please help!
>
> To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
>
> An example:
> stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');

I knew these thing,the function.I dont know what should I put instead of Intensity_image???
My code:

I = imread('pvs6multiscale1j.jpg');
imshow(I);
threshold = graythresh(I);
bw = im2bw(I,threshold);

% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,180);


L=bwlabel(bw,8);
stats=regionprops(L, _______ ,'MeanIntensity');

Subject: MeanIntensity

From: Jeff

Date: 20 Jul, 2011 23:05:25

Message: 4 of 16

"Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > Hello,
> > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > I got these errors:
> > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > Size of I doesn't match size information found in the first input argument.
> > >
> > > Error in ==> regionprops at 154
> > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > please help!
> >
> > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> >
> > An example:
> > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
>
> I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> My code:
>
> I = imread('pvs6multiscale1j.jpg');
> imshow(I);
> threshold = graythresh(I);
> bw = im2bw(I,threshold);
>
> % remove all object containing fewer than 30 pixels
> bw = bwareaopen(bw,180);
>
>
> L=bwlabel(bw,8);
> stats=regionprops(L, _______ ,'MeanIntensity');

In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:

gray_img = rgb2gray(I);
L=bwlabel(bw, 8);
stats = regionprops(L, gray_img, 'MeanIntensity');

Subject: MeanIntensity

From: Aikerim

Date: 21 Jul, 2011 08:36:09

Message: 5 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > Hello,
> > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > I got these errors:
> > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > Size of I doesn't match size information found in the first input argument.
> > > >
> > > > Error in ==> regionprops at 154
> > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > please help!
> > >
> > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > >
> > > An example:
> > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> >
> > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > My code:
> >
> > I = imread('pvs6multiscale1j.jpg');
> > imshow(I);
> > threshold = graythresh(I);
> > bw = im2bw(I,threshold);
> >
> > % remove all object containing fewer than 30 pixels
> > bw = bwareaopen(bw,180);
> >
> >
> > L=bwlabel(bw,8);
> > stats=regionprops(L, _______ ,'MeanIntensity');
>
> In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
>
> gray_img = rgb2gray(I);
> L=bwlabel(bw, 8);
> stats = regionprops(L, gray_img, 'MeanIntensity');

Hi,
But my image is already in grayscale I mean the original image (I)???

Subject: MeanIntensity

From: Jeff

Date: 21 Jul, 2011 15:58:09

Message: 6 of 16

"Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > Hello,
> > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > I got these errors:
> > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > Size of I doesn't match size information found in the first input argument.
> > > > >
> > > > > Error in ==> regionprops at 154
> > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > please help!
> > > >
> > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > >
> > > > An example:
> > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > >
> > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > My code:
> > >
> > > I = imread('pvs6multiscale1j.jpg');
> > > imshow(I);
> > > threshold = graythresh(I);
> > > bw = im2bw(I,threshold);
> > >
> > > % remove all object containing fewer than 30 pixels
> > > bw = bwareaopen(bw,180);
> > >
> > >
> > > L=bwlabel(bw,8);
> > > stats=regionprops(L, _______ ,'MeanIntensity');
> >
> > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> >
> > gray_img = rgb2gray(I);
> > L=bwlabel(bw, 8);
> > stats = regionprops(L, gray_img, 'MeanIntensity');
>
> Hi,
> But my image is already in grayscale I mean the original image (I)???

Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
1 - post the results of size(L) as well as size(I)
2 - post your original image somewhere so we can download it and run it through your code

Subject: MeanIntensity

From: Aikerim

Date: 21 Jul, 2011 16:20:10

Message: 7 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > Hello,
> > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > I got these errors:
> > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > >
> > > > > > Error in ==> regionprops at 154
> > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > please help!
> > > > >
> > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > >
> > > > > An example:
> > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > >
> > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > My code:
> > > >
> > > > I = imread('pvs6multiscale1j.jpg');
> > > > imshow(I);
> > > > threshold = graythresh(I);
> > > > bw = im2bw(I,threshold);
> > > >
> > > > % remove all object containing fewer than 30 pixels
> > > > bw = bwareaopen(bw,180);
> > > >
> > > >
> > > > L=bwlabel(bw,8);
> > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > >
> > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > >
> > > gray_img = rgb2gray(I);
> > > L=bwlabel(bw, 8);
> > > stats = regionprops(L, gray_img, 'MeanIntensity');
> >
> > Hi,
> > But my image is already in grayscale I mean the original image (I)???
>
> Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> 1 - post the results of size(L) as well as size(I)
> 2 - post your original image somewhere so we can download it and run it through your code

Could u try this link:
http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/

Subject: MeanIntensity

From: Jeff

Date: 21 Jul, 2011 16:52:09

Message: 8 of 16

"Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > Hello,
> > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > I got these errors:
> > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > >
> > > > > > > Error in ==> regionprops at 154
> > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > please help!
> > > > > >
> > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > >
> > > > > > An example:
> > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > >
> > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > My code:
> > > > >
> > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > imshow(I);
> > > > > threshold = graythresh(I);
> > > > > bw = im2bw(I,threshold);
> > > > >
> > > > > % remove all object containing fewer than 30 pixels
> > > > > bw = bwareaopen(bw,180);
> > > > >
> > > > >
> > > > > L=bwlabel(bw,8);
> > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > >
> > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > >
> > > > gray_img = rgb2gray(I);
> > > > L=bwlabel(bw, 8);
> > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > >
> > > Hi,
> > > But my image is already in grayscale I mean the original image (I)???
> >
> > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > 1 - post the results of size(L) as well as size(I)
> > 2 - post your original image somewhere so we can download it and run it through your code
>
> Could u try this link:
> http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/

Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.

In any case, the following code works with the image you provided:

I = imread('pvs6multiscale1j.jpg');
imshow(I);
threshold = graythresh(I);
bw = im2bw(I,threshold);

% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,180);

L=bwlabel(bw,8);
stats=regionprops(L, I ,'MeanIntensity');

Subject: MeanIntensity

From: Aikerim

Date: 21 Jul, 2011 17:07:09

Message: 9 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j09lfp$d69$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> > "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > > Hello,
> > > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > > I got these errors:
> > > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > > >
> > > > > > > > Error in ==> regionprops at 154
> > > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > > please help!
> > > > > > >
> > > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > > >
> > > > > > > An example:
> > > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > > >
> > > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > > My code:
> > > > > >
> > > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > > imshow(I);
> > > > > > threshold = graythresh(I);
> > > > > > bw = im2bw(I,threshold);
> > > > > >
> > > > > > % remove all object containing fewer than 30 pixels
> > > > > > bw = bwareaopen(bw,180);
> > > > > >
> > > > > >
> > > > > > L=bwlabel(bw,8);
> > > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > > >
> > > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > > >
> > > > > gray_img = rgb2gray(I);
> > > > > L=bwlabel(bw, 8);
> > > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > > >
> > > > Hi,
> > > > But my image is already in grayscale I mean the original image (I)???
> > >
> > > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > > 1 - post the results of size(L) as well as size(I)
> > > 2 - post your original image somewhere so we can download it and run it through your code
> >
> > Could u try this link:
> > http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/
>
> Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.
>
> In any case, the following code works with the image you provided:
>
> I = imread('pvs6multiscale1j.jpg');
> imshow(I);
> threshold = graythresh(I);
> bw = im2bw(I,threshold);
>
> % remove all object containing fewer than 30 pixels
> bw = bwareaopen(bw,180);
>
> L=bwlabel(bw,8);
> stats=regionprops(L, I ,'MeanIntensity');
That's image is after the segmentation, it's my objective image,so it's strange it doesn't work on my Matlab (2009).It gives the mentioned before errors about 'not matching'...anyway,thank you!

Subject: MeanIntensity

From: Jeff

Date: 21 Jul, 2011 18:13:09

Message: 10 of 16

"Aikerim" wrote in message <j09mbt$g02$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <j09lfp$d69$1@newscl01ah.mathworks.com>...
> > "Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> > > "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > > > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > > > Hello,
> > > > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > > > I got these errors:
> > > > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > > > >
> > > > > > > > > Error in ==> regionprops at 154
> > > > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > > > please help!
> > > > > > > >
> > > > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > > > >
> > > > > > > > An example:
> > > > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > > > >
> > > > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > > > My code:
> > > > > > >
> > > > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > > > imshow(I);
> > > > > > > threshold = graythresh(I);
> > > > > > > bw = im2bw(I,threshold);
> > > > > > >
> > > > > > > % remove all object containing fewer than 30 pixels
> > > > > > > bw = bwareaopen(bw,180);
> > > > > > >
> > > > > > >
> > > > > > > L=bwlabel(bw,8);
> > > > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > > > >
> > > > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > > > >
> > > > > > gray_img = rgb2gray(I);
> > > > > > L=bwlabel(bw, 8);
> > > > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > > > >
> > > > > Hi,
> > > > > But my image is already in grayscale I mean the original image (I)???
> > > >
> > > > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > > > 1 - post the results of size(L) as well as size(I)
> > > > 2 - post your original image somewhere so we can download it and run it through your code
> > >
> > > Could u try this link:
> > > http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/
> >
> > Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.
> >
> > In any case, the following code works with the image you provided:
> >
> > I = imread('pvs6multiscale1j.jpg');
> > imshow(I);
> > threshold = graythresh(I);
> > bw = im2bw(I,threshold);
> >
> > % remove all object containing fewer than 30 pixels
> > bw = bwareaopen(bw,180);
> >
> > L=bwlabel(bw,8);
> > stats=regionprops(L, I ,'MeanIntensity');
> That's image is after the segmentation, it's my objective image,so it's strange it doesn't work on my Matlab (2009).It gives the mentioned before errors about 'not matching'...anyway,thank you!

Sorry, I wasn't specific enough. Please post your original image, the one you are reading in the first step.

Subject: MeanIntensity

From: Aikerim

Date: 21 Jul, 2011 18:25:10

Message: 11 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j09q7l$rje$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j09mbt$g02$1@newscl01ah.mathworks.com>...
> > "Jeff " <jea@gene.dot.com> wrote in message <j09lfp$d69$1@newscl01ah.mathworks.com>...
> > > "Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> > > > "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > > > > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > > > > Hello,
> > > > > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > > > > I got these errors:
> > > > > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > > > > >
> > > > > > > > > > Error in ==> regionprops at 154
> > > > > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > > > > please help!
> > > > > > > > >
> > > > > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > > > > >
> > > > > > > > > An example:
> > > > > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > > > > >
> > > > > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > > > > My code:
> > > > > > > >
> > > > > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > > > > imshow(I);
> > > > > > > > threshold = graythresh(I);
> > > > > > > > bw = im2bw(I,threshold);
> > > > > > > >
> > > > > > > > % remove all object containing fewer than 30 pixels
> > > > > > > > bw = bwareaopen(bw,180);
> > > > > > > >
> > > > > > > >
> > > > > > > > L=bwlabel(bw,8);
> > > > > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > > > > >
> > > > > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > > > > >
> > > > > > > gray_img = rgb2gray(I);
> > > > > > > L=bwlabel(bw, 8);
> > > > > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > > > > >
> > > > > > Hi,
> > > > > > But my image is already in grayscale I mean the original image (I)???
> > > > >
> > > > > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > > > > 1 - post the results of size(L) as well as size(I)
> > > > > 2 - post your original image somewhere so we can download it and run it through your code
> > > >
> > > > Could u try this link:
> > > > http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/
> > >
> > > Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.
> > >
> > > In any case, the following code works with the image you provided:
> > >
> > > I = imread('pvs6multiscale1j.jpg');
> > > imshow(I);
> > > threshold = graythresh(I);
> > > bw = im2bw(I,threshold);
> > >
> > > % remove all object containing fewer than 30 pixels
> > > bw = bwareaopen(bw,180);
> > >
> > > L=bwlabel(bw,8);
> > > stats=regionprops(L, I ,'MeanIntensity');
> > That's image is after the segmentation, it's my objective image,so it's strange it doesn't work on my Matlab (2009).It gives the mentioned before errors about 'not matching'...anyway,thank you!
>
> Sorry, I wasn't specific enough. Please post your original image, the one you are reading in the first step.

http://imageshack.us/photo/my-images/825/pvs6.jpg/ here's an initial image before segmentation.but i should use the another one (in previous link)

Subject: MeanIntensity

From: Jeff

Date: 21 Jul, 2011 19:25:11

Message: 12 of 16

"Aikerim" wrote in message <j09qu6$m7$1@newscl01ah.mathworks.com>...
> "Jeff " <jea@gene.dot.com> wrote in message <j09q7l$rje$1@newscl01ah.mathworks.com>...
> > "Aikerim" wrote in message <j09mbt$g02$1@newscl01ah.mathworks.com>...
> > > "Jeff " <jea@gene.dot.com> wrote in message <j09lfp$d69$1@newscl01ah.mathworks.com>...
> > > > "Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> > > > > "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > > > > > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > > > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > > > > > Hello,
> > > > > > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > > > > > I got these errors:
> > > > > > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > > > > > >
> > > > > > > > > > > Error in ==> regionprops at 154
> > > > > > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > > > > > please help!
> > > > > > > > > >
> > > > > > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > > > > > >
> > > > > > > > > > An example:
> > > > > > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > > > > > >
> > > > > > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > > > > > My code:
> > > > > > > > >
> > > > > > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > > > > > imshow(I);
> > > > > > > > > threshold = graythresh(I);
> > > > > > > > > bw = im2bw(I,threshold);
> > > > > > > > >
> > > > > > > > > % remove all object containing fewer than 30 pixels
> > > > > > > > > bw = bwareaopen(bw,180);
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > L=bwlabel(bw,8);
> > > > > > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > > > > > >
> > > > > > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > > > > > >
> > > > > > > > gray_img = rgb2gray(I);
> > > > > > > > L=bwlabel(bw, 8);
> > > > > > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > > > > > >
> > > > > > > Hi,
> > > > > > > But my image is already in grayscale I mean the original image (I)???
> > > > > >
> > > > > > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > > > > > 1 - post the results of size(L) as well as size(I)
> > > > > > 2 - post your original image somewhere so we can download it and run it through your code
> > > > >
> > > > > Could u try this link:
> > > > > http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/
> > > >
> > > > Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.
> > > >
> > > > In any case, the following code works with the image you provided:
> > > >
> > > > I = imread('pvs6multiscale1j.jpg');
> > > > imshow(I);
> > > > threshold = graythresh(I);
> > > > bw = im2bw(I,threshold);
> > > >
> > > > % remove all object containing fewer than 30 pixels
> > > > bw = bwareaopen(bw,180);
> > > >
> > > > L=bwlabel(bw,8);
> > > > stats=regionprops(L, I ,'MeanIntensity');
> > > That's image is after the segmentation, it's my objective image,so it's strange it doesn't work on my Matlab (2009).It gives the mentioned before errors about 'not matching'...anyway,thank you!
> >
> > Sorry, I wasn't specific enough. Please post your original image, the one you are reading in the first step.
>
> http://imageshack.us/photo/my-images/825/pvs6.jpg/ here's an initial image before segmentation.but i should use the another one (in previous link)

Huh. Well, I don't understand why you need the mean intensity of a binary mask image (your pv6multiscale). The "mean intensity" of a binary mask would always be 1, or 255, or whatever value is assigned to the white pixels, no matter what shape the region is...unless the mask has holes it in, which yours does not.
Typically, one would create a binary mask and then use that to determine the mean intensity in the original image. If this is what you are interested in, try the following:

I = imread('pvs6.jpg');
threshold = graythresh(I);
bw = ~im2bw(I,threshold);
bw = imfill(bw, 'holes');

% remove all object containing fewer than 30 pixels
bw = bwareaopen(bw,180);

L=bwlabel(bw,8);
stats=regionprops(L, I ,'MeanIntensity');

If this is not what you're interested in, you'll need to be a bit more specific.

Subject: MeanIntensity

From: Aikerim

Date: 21 Jul, 2011 19:41:09

Message: 13 of 16

"Jeff " <jea@gene.dot.com> wrote in message <j09uen$bcd$1@newscl01ah.mathworks.com>...
> "Aikerim" wrote in message <j09qu6$m7$1@newscl01ah.mathworks.com>...
> > "Jeff " <jea@gene.dot.com> wrote in message <j09q7l$rje$1@newscl01ah.mathworks.com>...
> > > "Aikerim" wrote in message <j09mbt$g02$1@newscl01ah.mathworks.com>...
> > > > "Jeff " <jea@gene.dot.com> wrote in message <j09lfp$d69$1@newscl01ah.mathworks.com>...
> > > > > "Aikerim" wrote in message <j09jjq$7n6$1@newscl01ah.mathworks.com>...
> > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j09iah$3nd$1@newscl01ah.mathworks.com>...
> > > > > > > "Aikerim" wrote in message <j08odp$jrq$1@newscl01ah.mathworks.com>...
> > > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07mvl$o8$1@newscl01ah.mathworks.com>...
> > > > > > > > > "Aikerim" wrote in message <j07cbq$214$1@newscl01ah.mathworks.com>...
> > > > > > > > > > "Jeff " <jea@gene.dot.com> wrote in message <j07b4d$rj9$1@newscl01ah.mathworks.com>...
> > > > > > > > > > > "Aikerim" wrote in message <j078r9$kbe$1@newscl01ah.mathworks.com>...
> > > > > > > > > > > > Hello,
> > > > > > > > > > > > Could someone provide me with an example (code) of meanintensity finding.I should calculate the mean object intensity in the range 0-100. I've tried regionprops (L,I,'MeanIntensity') , how to understand that size (I) must to be equal size (L) how to write or set it?
> > > > > > > > > > > > I got these errors:
> > > > > > > > > > > > ??? Error using ==> regionprops>ParseInputs at 1112
> > > > > > > > > > > > Size of I doesn't match size information found in the first input argument.
> > > > > > > > > > > >
> > > > > > > > > > > > Error in ==> regionprops at 154
> > > > > > > > > > > > [I,requestedStats,officialStats] = ParseInputs(imageSize, varargin{:});
> > > > > > > > > > > > please help!
> > > > > > > > > > >
> > > > > > > > > > > To calculate mean intensity, regionprops needs the raw image in addition to a labeled or binary image:
> > > > > > > > > > > STATS = regionprops(..., I, properties) measures a set of properties for each labeled region in the image I. The first input to regionprops—either BW, CC, or L—identifies the regions in I. The sizes must match: size(I) must equal size(BW), CC.ImageSize, or size(L).
> > > > > > > > > > >
> > > > > > > > > > > An example:
> > > > > > > > > > > stats = regionprops(BW_image, Intensity_image, 'MeanIntensity');
> > > > > > > > > >
> > > > > > > > > > I knew these thing,the function.I dont know what should I put instead of Intensity_image???
> > > > > > > > > > My code:
> > > > > > > > > >
> > > > > > > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > > > > > > imshow(I);
> > > > > > > > > > threshold = graythresh(I);
> > > > > > > > > > bw = im2bw(I,threshold);
> > > > > > > > > >
> > > > > > > > > > % remove all object containing fewer than 30 pixels
> > > > > > > > > > bw = bwareaopen(bw,180);
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > L=bwlabel(bw,8);
> > > > > > > > > > stats=regionprops(L, _______ ,'MeanIntensity');
> > > > > > > > >
> > > > > > > > > In this context, regionprops requires a grayscale image. The easiest way to do this is to use RGB2GRAY, but there are other ways:
> > > > > > > > >
> > > > > > > > > gray_img = rgb2gray(I);
> > > > > > > > > L=bwlabel(bw, 8);
> > > > > > > > > stats = regionprops(L, gray_img, 'MeanIntensity');
> > > > > > > >
> > > > > > > > Hi,
> > > > > > > > But my image is already in grayscale I mean the original image (I)???
> > > > > > >
> > > > > > > Are you sure it is in grayscale, and not an RGB that looks like it is grayscale? Do one of two things:
> > > > > > > 1 - post the results of size(L) as well as size(I)
> > > > > > > 2 - post your original image somewhere so we can download it and run it through your code
> > > > > >
> > > > > > Could u try this link:
> > > > > > http://imageshack.us/photo/my-images/851/pvs6multiscale1j.jpg/
> > > > >
> > > > > Are you sure that's the right image? It looks like a binary mask displayed in matlab then saved.
> > > > >
> > > > > In any case, the following code works with the image you provided:
> > > > >
> > > > > I = imread('pvs6multiscale1j.jpg');
> > > > > imshow(I);
> > > > > threshold = graythresh(I);
> > > > > bw = im2bw(I,threshold);
> > > > >
> > > > > % remove all object containing fewer than 30 pixels
> > > > > bw = bwareaopen(bw,180);
> > > > >
> > > > > L=bwlabel(bw,8);
> > > > > stats=regionprops(L, I ,'MeanIntensity');
> > > > That's image is after the segmentation, it's my objective image,so it's strange it doesn't work on my Matlab (2009).It gives the mentioned before errors about 'not matching'...anyway,thank you!
> > >
> > > Sorry, I wasn't specific enough. Please post your original image, the one you are reading in the first step.
> >
> > http://imageshack.us/photo/my-images/825/pvs6.jpg/ here's an initial image before segmentation.but i should use the another one (in previous link)
>
> Huh. Well, I don't understand why you need the mean intensity of a binary mask image (your pv6multiscale). The "mean intensity" of a binary mask would always be 1, or 255, or whatever value is assigned to the white pixels, no matter what shape the region is...unless the mask has holes it in, which yours does not.
> Typically, one would create a binary mask and then use that to determine the mean intensity in the original image. If this is what you are interested in, try the following:
>
> I = imread('pvs6.jpg');
> threshold = graythresh(I);
> bw = ~im2bw(I,threshold);
> bw = imfill(bw, 'holes');
>
> % remove all object containing fewer than 30 pixels
> bw = bwareaopen(bw,180);
>
> L=bwlabel(bw,8);
> stats=regionprops(L, I ,'MeanIntensity');
>
> If this is not what you're interested in, you'll need to be a bit more specific.

Thank you Jeff so much, I understand all these things but that's a task 'to find the mean object intensity in the range 0-100':)so...Thank you!!!

Subject: MeanIntensity

From: ImageAnalyst

Date: 23 Jul, 2011 22:13:20

Message: 14 of 16

On Jul 21, 3:41 pm, "Aikerim " <keri...@mail.ru> wrote:
> Thank you Jeff so much, I understand all these things but that's a task 'to find the mean object intensity in the range 0-100':)so...Thank you!!!
---------------------------------------------------------------------
Aikerim :
What do you mean by "that's a task"? Do you mean "it is difficult for
me"? Or do you mean "My assigned task is to find...."? Or something
else?

What do you mean by "find the mean object intensity in the range
0-100"? This seems to be a new criteria you just added. You didn't
mention anything about the 0-100 range before. This should be a
trivial problem, even with the new "0-100" requirement, especially
with the code Jeff gave you.

And getting back to your original question, how on earth did your
original and labeled image get to have different sizes like the error
message indicated?

Do you have this problem solved yet or not? Your last post is unclear
on that.
ImageAnalyst

Subject: MeanIntensity

From: Aikerim

Date: 24 Jul, 2011 10:35:08

Message: 15 of 16

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <d51e3592-5d8a-4913-85ad-149d2007862b@t7g2000vbv.googlegroups.com>...
> On Jul 21, 3:41 pm, "Aikerim " <keri...@mail.ru> wrote:
> > Thank you Jeff so much, I understand all these things but that's a task 'to find the mean object intensity in the range 0-100':)so...Thank you!!!
> ---------------------------------------------------------------------
> Aikerim :
> What do you mean by "that's a task"? Do you mean "it is difficult for
> me"? Or do you mean "My assigned task is to find...."? Or something
> else?
>
> What do you mean by "find the mean object intensity in the range
> 0-100"? This seems to be a new criteria you just added. You didn't
> mention anything about the 0-100 range before. This should be a
> trivial problem, even with the new "0-100" requirement, especially
> with the code Jeff gave you.
>
> And getting back to your original question, how on earth did your
> original and labeled image get to have different sizes like the error
> message indicated?
>
> Do you have this problem solved yet or not? Your last post is unclear
> on that.
> ImageAnalyst
Hi,
The initially assigned task is to find the mean intensity (0-100),I understood that 0-100 is percentage if e.g the intensity is from 0 to 255, I should find the percentage of it.
Unfortunately, I couldnt get any results using the original image with the code. There are still the mentioned errors .I dont know whats a problem,if Jeff said that the code works. Maybe with Matlab or PC,I've tried to restart Matlab...but anyway no changes.

Subject: MeanIntensity

From: ImageAnalyst

Date: 24 Jul, 2011 13:37:59

Message: 16 of 16

On Jul 24, 6:35 am, "Aikerim " <keri...@mail.ru> wrote:
> Hi,
> The initially assigned task is to find the mean intensity (0-100),I understood that 0-100 is percentage if e.g the intensity is from 0 to 255, I should find the percentage of it.
> Unfortunately, I couldnt get any results using the original image with the code. There are still the mentioned errors .I dont know whats a problem,if Jeff said that the code works. Maybe with Matlab or PC,I've tried to restart Matlab...but anyway no changes.

---------------------------------------------------------------------
Did you look up "mean" in the help? If you had you would have found
the mean and mean2 functions. Then it's a trivial step to simply do
meanPercent = mean(grayImage(binaryImage))/255;

Here's the full demo:

% Demo to find the mean gray leve of pixels less than some threshold.
% By ImageAnalyst

% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.

clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
baseFileName = 'eight.tif';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

% Specify a threshold.
thresholdValue = 185;
% Draw it on the histogram.
hold on;
yRange = YLim;
line([thresholdValue thresholdValue], [0 yRange(2)], ...
'LineWidth', 2, 'Color', 'r');
% Threshold the image.
binaryImage = grayImage < thresholdValue;
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage, []);
title('Thresholded (Binary) Image', 'FontSize', fontSize);

% Just for fun, mask the image to show only those pixels.
% This will be a 2D image.
maskedImage = grayImage .* uint8(binaryImage);
% Display the Masked image.
subplot(2, 2, 4);
imshow(maskedImage, [0 255]);
title('Masked Image', 'FontSize', fontSize);

% Get a list of only the pixels that have a gray level
% less than the threshold value. It's a column vector.
onlyGLsLessThanThreshold = grayImage(binaryImage);

% Get the mean of those pixels.
meanGL = mean(onlyGLsLessThanThreshold)
% Divide by 255 to get in the range 0-100.
meanPercent = meanGL / 255 * 100

message = sprintf('Done with demo!\nMean gray level of masked pixels =
%.4f.\nAs a percent of 255 that is %.3f%%.',...
meanGL, meanPercent);
msgbox(message);

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us