Color differentation in the image

Hi All,
Is there any code to find differentation in the image?

 Accepted Answer

Image Analyst
Image Analyst on 15 Feb 2014
What do you mean by differentiation? I have several color segmentation demos in my File Exchange if that's what you mean: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

26 Comments

Thanks for your response,I have many coloured images some of them contains some color (red,blue,brown,and black)what I need to know how can I detect the color variation in the segmented image(ROI),could you help me by demo please?
Image Analyst
Image Analyst on 15 Feb 2014
Edited: Image Analyst on 15 Feb 2014
If you have objects with a variety of vivid colors, then it's probably best to threshold the saturation image. See my Color segmentation using HSV demo in my File Exchange, or see this answer: http://www.mathworks.com/matlabcentral/answers/116126#answer_124379 Or perhaps you'd like this: http://www.mathworks.com/matlabcentral/fileexchange/37197-dem-diffused-expectation-maximisation-for-image-segmentation
Please could you take a look to some my images that attached
OK, once you attach them.
hamed abdulaziz
hamed abdulaziz on 15 Feb 2014
Moved: DGM on 30 Dec 2023
hamed abdulaziz
hamed abdulaziz on 15 Feb 2014
Moved: DGM on 30 Dec 2023
hamed abdulaziz
hamed abdulaziz on 15 Feb 2014
Moved: DGM on 30 Dec 2023
hamed abdulaziz
hamed abdulaziz on 15 Feb 2014
Moved: DGM on 30 Dec 2023
Where these image are melanoma and the color variation is one of the features to detect this disease
Yes, calculating delta E and then getting the histogram, mean, and std dev of that should be good.
Could you explain by demo please,thanks in advance
Image Analyst
Image Analyst on 15 Feb 2014
Edited: Image Analyst on 15 Feb 2014
This demo shows you how to calculate the delta E image and get its histogram. http://www.mathworks.com/matlabcentral/fileexchange/31118-color-segmentation-by-delta-e-color-difference.
hamed abdulaziz
hamed abdulaziz on 15 Feb 2014
Edited: hamed abdulaziz on 15 Feb 2014
OK, I will accept please could adapt your excellent demo for calculating delta E and then getting the histogram, mean, and std dev for use it with my images ,thanks
Image Analyst : please could you help me for calculating delta E and then getting the histogram, mean, and std dev for use it with my images ,thanks
Make sure you take the mask into account.
pixelsInsideMask = deltaE(mask); % 1D vector of pixels only within mask.
counts = hist(pixelsInsideMask, numberOfBins);
meanDeltaE = mean(pixelsInsideMask(:));
SDDeltaE = std(pixelsInsideMask(:));
Ok , I tried your demo but I need to all operation automatically (not clicking by mouse) what I need is to get the color variation as a indication for disease feature
You just change/adapt it so that it takes the mean color from your whole image (or the masked part). Do you know how to do that?
hamed abdulaziz
hamed abdulaziz on 16 Feb 2014
Edited: hamed abdulaziz on 16 Feb 2014
I don't know how to do that?please could you change the demo to work with my images,thanks.
Find the mask something like this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Find where all of them are zero.
mask = redChannel == 0 & greenChannel == 0 & blueChannel == 0;
Then convert rgb to lab and get mean lab like this:
meanL = mean(lChannel(mask));
meanA = mean(aChannel(mask));
meanB = mean(bChannel(mask));
Then how can I get the DELTA E after getting the meanL ,meanA,and meanB ?
Like it shows in the demo:
% Make uniform images of only that one single LAB color.
LStandard = LMean * ones(rows, columns);
aStandard = aMean * ones(rows, columns);
bStandard = bMean * ones(rows, columns);
% Create the delta images: delta L, delta A, and delta B.
deltaL = LChannel - LStandard;
deltaa = aChannel - aStandard;
deltab = bChannel - bStandard;
% Create the Delta E image.
% This is an image that represents the color difference.
% Delta E is the square root of the sum of the squares of the delta images.
deltaE = sqrt(deltaL .^ 2 + deltaa .^ 2 + deltab .^ 2);
% Mask it to get the Delta E in the mask region only.
maskedDeltaE = deltaE .* mask;
% Get the mean delta E in the mask region
% Note: deltaE(mask) is a 1D vector of ONLY the pixel values within the masked area.
meanMaskedDeltaE = mean(deltaE(mask));
where meanL is just Lmean by a different name.
hamed abdulaziz
hamed abdulaziz on 17 Feb 2014
Edited: hamed abdulaziz on 17 Feb 2014
how can determine the the number of(rows and columns) in the
LStandard = LMean *
ones(rows, columns);
and can I use the value of deltaE in the
deltaE = sqrt(deltaL
.^ 2 + deltaa .^ 2 +
deltab .^ 2);
as a feature for color variation?
I tried this code
clear all;
clc;
close all;
% rgbImage= imread('D:\final_segmentation\segmentation_abnormal\200AC.BMP');
rgbImage= imread('D:\3.BMP');
% Find the mask something like this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Find where all of them are zero.
mask = redChannel ==
0 & greenChannel ==
0 & blueChannel ==
0; % Then convert rgb to lab and get mean lab like this:
% Convert image from RGB colorspace to lab color space.
cform =
makecform('srgb2lab'
);
lab_Image =
applycform(im2double
(rgbImage),cform); % Extract out the color bands from the original image % into 3 separate 2D arrays, one for each color component.
LChannel = lab_Image(:, :, 1);
aChannel = lab_Image(:, :, 2);
bChannel = lab_Image(:, :, 3);
LMean =
mean(LChannel(mask));
aMean =
mean(aChannel(mask));
bMean =
mean(bChannel(mask));
[rows,
columns]=size(LChann
el);
% Make uniform images of only that one single LAB color.
LStandard = LMean *
ones(rows, columns);
aStandard = aMean *
ones(rows, columns);
bStandard = bMean *
ones(rows, columns); % Create the delta images: delta L, delta A, and delta B.
deltaL = LChannel - LStandard;
deltaa = aChannel - aStandard;
deltab = bChannel - bStandard; % Create the Delta E image. % This is an image that represents the color difference. % Delta E is the square root of the sum of the squares of the delta images.
deltaE = sqrt(deltaL .^ 2 + deltaa .^ 2 + deltab .^ 2);
but I always get deltaE = zero
thank you
That's from a line earlier in the demo:
[rows, columns, numberOfColorBands] = size(rgbImage);
THANK YOU I ATTACHED WAHT I TRIED (MY_DELTA_E) CODE HOW CAN USE FOR COLOR VARIATION INDICATOR PLEASE COULD CHECK IT FOR CORRECTNESS THANK YOU
hamed abdulaziz
hamed abdulaziz on 17 Feb 2014
Moved: DGM on 30 Dec 2023
I ATTACHED WAHT I TRIED (MY_DELTA_E) CODE HOW CAN USE DELTA_E FOR COLOR VARIATION INDICATOR PLEASE COULD CHECK IT FOR CORRECTNESS
Looks about right for as far as you got. You just need to complete it to find the variation using code I gave you in my answer:
pixelsInsideMask = deltaE(mask); % 1D vector of pixels only within mask.
counts = hist(pixelsInsideMask, numberOfBins);
meanDeltaE = mean(pixelsInsideMask(:));
SDDeltaE = std(pixelsInsideMask(:));
hamed abdulaziz
hamed abdulaziz on 17 Feb 2014
Moved: DGM on 30 Dec 2023
Please did you check (MY_DELTA_E) CODE wher do I add your code?could you complet it and check it on the above images,thanks
pixelsInsideMask = deltaE(mask); % 1D vector of pixels only within mask.
counts = hist(pixelsInsideMask, numberOfBins);
meanDeltaE = mean(pixelsInsideMask(:));
SDDeltaE = std(pixelsInsideMask(:));

Sign in to comment.

More Answers (0)

Asked:

on 15 Feb 2014

Moved:

DGM
on 30 Dec 2023

Community Treasure Hunt

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

Start Hunting!