I am getting an error while running regionprops. How?

[L,N] = superpixels(I,50);% superpixels=44
props = regionprops(L,'MeanIntensity','PixelValues','PixelList','PixelIdxList');
I am getting this error."REGIONPROPS needs I as an input to calculate 'MeanIntensity'".
Thankyou

Answers (2)

You need to pass in the original image. You can't just pass in the labeled image. If you want the mean intensity of regions in an image, of course you need to pass in the image itself. The labeled image L merely tells where the regions are in the original image. You have to pass in the image itself as the second argument if you want to measure its intensities in those regions.

13 Comments

Thank you so much for your reply.I am using "Lab" Image
[L,N] = superpixels(I,50);% superpixels=44
lprops = regionprops(L,I(:,:,1),'MeanIntensity','PixelValues','PixelList','PixelIdxList'); % working fine
props = regionprops(L,I,'MeanIntensity','PixelValues','PixelList','PixelIdxList');
%Error using iptassert (line 19)
Size of I doesn't match size information found in the first input argument.(L value 400*300 double; I value 400*300*3 double)
So I have changed L value
props = regionprops(LRGBDOUBLE,I,'MeanIntensity','PixelValues','PixelList','PixelIdxList');% L=400*300*3 double;I value 400*300*3 double
props =1*1 struct ; PixelIDX=108802x1 double;PixelList= 108802x3 double; PIxelValues=108802x1 double; MeanIntensity= 22.162436705797077"
How to get MeanIntensity for all 44 superpixels?*Use 3 channles l,a,b for each superpixel ( for example first 3 superpixels L1=68.50;L2=61.70;L3=40.65; a1=0.26;a2=-3.89;a3=-14.52 b1=-5.59;b2=4.00;b3=29.51 )
Yes, you have to pass in each color channel separately, not a 3-D RGB or LAB or HSV image. Like
L_Image = labImage(:, :, 1); % Extract the L channel.
props = regionprops(L, L_Image,'MeanIntensity','.......
Note, you used:
[L,N] = superpixels(I.......
following the Mathworks example of using crummy variable names. So I think you got confused between that L and the L of LAB color space. Be careful. The badly named L returned from superpixels is actually a labeled image, not the L color space image. It would be better to use descriptive variable names like
[labeledImage, numberOfLabels] = superpixels(.....
labImage = rgb2lab(rgbImage);
L_Image = labImage(:, :, 1); % Extract the L channel only.
A_Image = labImage(:, :, 2); % Extract the A channel only.
B_Image = labImage(:, :, 3); % Extract the B channel only.
propsL = regionprops(labeledImage, L_Image,'MeanIntensity','.......
propsA = regionprops(labeledImage, A_Image,'MeanIntensity','.......
propsB = regionprops(labeledImage, B_Image,'MeanIntensity','.......
Now you can get the mean value of each superpixel in each of the L, A, and B color channels.
adi  k
adi k on 20 Apr 2017
Edited: adi k on 20 Apr 2017
get the mean values of each superpixel in each of the L, A, and B color channels.
Q1: How can I get the meanvalue of the superpixel1 for the whole lab image? for example superpixel1 LAB meanintensity is (L1+A1+B1)/3; is it right?
That is not right. Summing A and B into L would make no physical sense whatsoever and I recommend you don't do it so I'm not going to tell you how. It would be like describing a person by adding together their weight and height and age. It just doesn't make sense.
Can I use this for each superpixel?
Yes, you can do that. That is computing the Delta E color difference. It's doing the square root of the sum of the squares of differences between L, a, and b, and that is valid, whereas just summing an L, a, and b by themselves is not valid.
I got distance matrix something
like this. How to convert superpixel properties to individual pixel properties?
You could take max(), min(), mean(), median(), or some kind of weighted average.
What reason did you have for calculating the distance matrix?
I don't even know what "How to convert superpixel properties to individual pixel properties?" means. And what is that matrix? Is that from pdist2() where you passed in the LAB values of all the superpixels, like
distances = pdist2(labValues, labValues);
If so, then the array contains the delta E (color difference) between every superpixel and every other superpixel. Not sure what you want to do after that because I totally don't understand your last sentence/question. You have the original value and know the locations (row, column) and color value of every individual pixel inside each superpixel, but I really don't know what you mean by "individual pixel properties" and how you'd get those from superpixels.
Superpixels are an aggregation of pixels into similar adjacent groupings. You always still have the original image so if you want something from the original image, just use it. You can't go backwards without the original image. It would be like saying I have the mean of the entire image, now tell me the gray level of all the individual pixels. You just can't do that.
I have generated 44 superpixels.Used this Delta E formula to calculate the color distance between one superpixel to all other superpixels. Now I have the distance matrix of 44*44(showed the sample matrix). I want to merge two superpixel regions if the distance betweeen them is low(because they are nearly exhibiting the same color). Then I want to display the image with modified superpixels regions.
<<
<<
>>
>>
Ad
Ad on 23 Apr 2017
Edited: Ad on 23 Apr 2017
@image analyst sir,
If I am using an RGB image, I can get the 44 superpixels values.(like R+G+B/3). I can display 44 superpixels and normalize them to [0 1] But I am using Lab color space, So as you mentioned above I can't do (L+A+B/3). I have values like this L1,A1,B1=S1; L2,A2,B2=S2; L3,A3,B3=S3; L4,A4,B4=S4;
How can I use Pdist2(labvalues,labvalues)?(I don't have single lab value for Supepixel1; I have S1=L1+A1+B1);
So that's why I want to calculate Distance matrix and then merge them if the color differnce between them is low.
If the color distance between P1 and P2 is "low", and the color distance between P2 and P3 is "low", but the color distance between P1 and P3 is not "low", then how do you want to handle the situation?
@walter Roberson sir,
Do you mean pixel or superpixel by P1? If P1 means pixel, that is why I want to convert superpixel properties to all pixels within that superpixel region.
Thank you so much for pointing that out.
How do know what are the superpixels connected to each other ?

Sign in to comment.

You are passing in a label matrix but asking for mean intensity. In order to do both at the same time you need to pass the intensity matrix as well. If I recall correctly you would pass it as the second argument.

Asked:

Ad
on 19 Apr 2017

Commented:

Ad
on 23 Apr 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!