I determined the shape of the object in image, how i can determine the object's color?
Afficher commentaires plus anciens
My project is about color and shape sorter, I used just two objects a circle and rectangle, Also three colors, Red, Green and blue. I determined what the shape is, But my problem now is how i can determine what the object color is? For example like this image.
clc
close all
clear
%%Reading Image And Save It In Array.
Image = 'Gertie-Ball-Image-Green-transparent.png';
RGBImage = imread(Image);
RGBImage = imresize(RGBImage,[500,500]);
subplot(2,2,1)
imshow(RGBImage)
title('Input Image')
%%Image Conversions To GrayScale.
GrayImage = rgb2gray(RGBImage);
subplot(2,2,2)
imshow(GrayImage)
title('GrayScale Image')
%%Binarize The Image.
BinaryImage = imbinarize(GrayImage);
subplot(2,2,3)
imshow(BinaryImage)
title('Initial (Noisy) Binary Image')
%%Remove Small Objects.
BinaryImage = bwareaopen(BinaryImage, 50);
% BinaryImage = imcomplement(BinaryImage); % Complement image
subplot(2,2,4)
imshow(BinaryImage)
title('Cleaned Binary Image')
%%Measure Properties Of BinaryImage Regions.
[LabeledImage, NumberOfObjects] = bwlabel(BinaryImage); % Label Connected Components In 2-D Binary Image.
Stats = regionprops('Table', LabeledImage, 'FilledArea','Perimeter');
%%Get The Outermost Boundaries Of The Objects.
FilledImage = imfill(BinaryImage, 'holes'); % Fill Image Regions And Holes.
Boundaries = bwboundaries(FilledImage); % Trace Region Boundaries In Binary Image.
%%Collect Some Of The Measurements Into Individual Arrays.
Perimeter = [Stats.Perimeter];
FilledArea = [Stats.FilledArea];
%%Calculate Circularies.
Circularities = Perimeter.^2./(4*pi*FilledArea);
%%Determaine The Shape
if Circularities(NumberOfObjects) < 1.10
disp Circle
elseif Circularities(NumberOfObjects) < 2.0
disp Square
else
disp Something
end
%%Determaine The Color.
3 commentaires
Adam
le 7 Mar 2018
If you have a mask representing your shape then isn't this simple, or am I missing something?
You'd have to take an average colour from applying the mask I guess, or if it is literally just red, green or blue and is supposed to be only one of those then you could just take the colour of any pixel known to be in your shape and calculate its distance from red, green and blue.
How you want to define colour distance is a whole other question and may or may not be relevant, depending how far away from the primary colours your shape may be.
odai kiwan
le 7 Mar 2018
Adam
le 7 Mar 2018
It all depends on how wide is the scope of objects and colours you will be presented with and what variation of colour they are allowed, but since you seemed to say only 3 colours are allowed - Red, Green and Blue, and that the shape must be one of these then a sample of pixels from inside the shape should do. Obviously just 1 is not very robust, but if your shape were uniformly very close to green or blue or red then it would still give the right answer. Since you appear to have white patches in your shape though a sampling of points with a mean (and exclusion of white) would work fine to give you the data to determine if it is red, green or blue.
Réponse acceptée
Plus de réponses (1)
murk hassan memon
le 11 Avr 2018
0 votes
But what about when we have object in biconcave or disc shape? what value should be use in order to represent the biconcave and disc shape? i am working on microscopic blood images and normal blood cells are biconcave or disc in shape. kindly help me out.
Catégories
En savoir plus sur Color Segmentation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!