i want to calculate the color features of soap only for that i mask BW ROI on an RGB soap image , i did the folowing code but the values are different when i calculte the color features byi croping only the soap image(with out the background)?Hlp

1 vue (au cours des 30 derniers jours)
I want to calculate the color features of soap only for that i mask BW ROI on an RGB soap image , i did the following code but the values are different when i calculate the color features by cropping only the soap image (without the background)? Hlp
&nbsp
clear all
clear
RGB=imread('soap170.jpg');
I=rgb2gray(RGB);
% Step 2: Create a Binary Image
level=graythresh(I);
BWgth = im2bw(I,level);
maskThreeChannel = repmat(BWgth , [1, 1, 3]);
RGB2=RGB;
RGB2(~maskThreeChannel)=0;
figure,imshow(RGB2); title('masked RGB')
R = double(RGB2(:, :, 1));
G = double(RGB2(:, :, 2));
B = double(RGB2(:, :, 3));
% compute 3 first color moments from each channel
meanR = mean( R(:) );
stdR = std( R(:) );
skewnessR = skewness(R(:));
meanG = mean( G(:) );
stdG = std( G(:) );
skewnessG = skewness(G(:));
meanB = mean( B(:) );
stdB = std( B(:) );
skewnessB = skewness(B(:));
% construct output vector
colorMoments = zeros(1, 9);
colorMoments(1, :) = [meanR stdR skewnessR meanG stdG skewnessG meanB stdB skewnessB]
  3 commentaires
solomon adenew
solomon adenew le 13 Août 2014
Modifié(e) : solomon adenew le 13 Août 2014
no no, the values when I calculate using mask on an RGB image are different from the values when I calculate with out masking, that is by cropping only the soap on the RGB image(with out the background)

Connectez-vous pour commenter.

Réponse acceptée

Yu Jiang
Yu Jiang le 13 Août 2014
Modifié(e) : Yu Jiang le 14 Août 2014
Hi Solomon
From what I understand, you would like to perform some masking operation on the original figure and would like to compare its color features with another figure, which is obtained by removing the background from the original figure. The issue you are facing is that the features of both figures are not the same while you are expecting them to be the same.
It seems that by masking the image, you set the background portion of the matrix RGB2 to be zero. However, RGB2 may not have the same color features as the cropped image. Let us take the channel R for example. The summation of R(:) will be the same as the summation of the corresponding vector R(:) in the cropped figure, since the values for the background are all zeros. However, when you are calculating the mean value of R(:) and its corresponding matrix in the cropped figure, the results will be different because they have different denominators (number of pixels). The same is true for the variance. Therefore, the color features will be different.
On the other hand, it seems that the masking operation you are trying to perform does not work, or at least is not necessary. Indeed, after executing the code you provided, if you try the following command in MATLAB
>> find((RGB2-RGB)~=0)
you will see the returned variable is an empty matrix, indicating RGB2 and RGB are identical. Therefore, the color features you calculated from the “masked” image are in fact the same color features of the original image. But I understand by performing this masking operation, you would like to assure that the figure’s background is purely black.
To help you achieve your goal, I would like to suggest you get rid of the zero elements in R, G, and B before calculating the color features, to do this, you may add the following three lines in your code, right before you calculate meanR.
R(R==0)=[];
G(G==0)=[];
B(B==0)=[];
Then, you should have color features similar to the ones from the cropped figure.
-Yu Jiang
  1 commentaire
solomon adenew
solomon adenew le 16 Août 2014
Modifié(e) : solomon adenew le 16 Août 2014
| you great and helpful thanks too much. Is it also in the same manner for texture manipulation of the ROI using graycomatrix ???
and i have already post the following question and i thougt you can also help me here
I am using a small Skype web cam for image acquisition into matlab, and It was possible to record videos and snapshot images using matlab code. but I want to change this web cam by Nikon D3100(more powerful) first I install the driver software that comes with it when it was bought. finally I connect it to my computer using USB but the matlab doesn't recognize it, when I write imaqhwinfo and when I search for all supported adaptors, i got nothing. help me, I am using MATLAB2012b
0 Comments|

Connectez-vous pour commenter.

Plus de réponses (1)

solomon adenew
solomon adenew le 15 Août 2014
Modifié(e) : solomon adenew le 15 Août 2014
you great and helpful thanks too much. Is it also the same manner for texture manipulation of the ROI using graycomatrix ???

Community Treasure Hunt

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

Start Hunting!

Translated by