How to Refine Color Identification Code?
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
For this project, I am trying to write code that can identify different colored skittles in a jpeg image and then report a count of (the number of) each different color skittle. So far, I have code that works decently using a binary method, but there are still issues; the count is often off somewhat. Also, before processing, the code first reduces the info in the image by pixelating it. This helps, but I have to modify how I resize the image for any given picture, which isn't ideal. The code should be able to work on any provided skittles image without being modified. I am not allowed to use loops of any kind. I have included my code. What are some ways I can refine it to work more precisely on any provided image?
% clear;clc;close all
Published=datestr(now, 21)
figure(1)
m = imread('skittles1.jpg');
imshow(m)
[X,map]= rgb2ind(m,5);
figure(2)
imshow(X,map);
RGB = ind2rgb(X,map);
figure
imshow(RGB)
BW = im2bw(RGB);
r=m(:,:,1);
g=m(:,:,2);
b=m(:,:,3);
y = [r > 185 & r < 260 & g > 190 & g < 255 & b > -1 & b < 100];
yt=sum(y(:));
o = [r > 165 & r < 260 & g > 15 & g < 90 & b > -1 & b < 30];
ot=sum(o(:));
gr = [r > 20 & r < 95 & g > 150 & g < 230 & b > -1 & b < 70];
grt=sum(gr(:));
re = [r > 100 & r < 230 & g > 3 & g < 35 & b > 5 & b < 55];
ret=sum(re(:));
p = [r > 5 & r < 117 & g > 0 & g < 130 & b > -1 & b < 150];
pt=sum(p(:));
loc = find(re==0);
loc1 = find(re==1);
r(loc1)=0;
g(loc1)=0;
b(loc1)=0;
r(loc)=255;
g(loc)=255;
b(loc)=255;
new=cat(3,r,g,b);
figure
BW = im2bw(new);
ComplementImage=imcomplement(BW);
HolesClearedImage = imfill(ComplementImage,'holes');
cc = bwconncomp(HolesClearedImage,18);
number = cc.NumObjects;
[labeledImage, numberOfObject] = bwlabel(HolesClearedImage);
measurements = regionprops(HolesClearedImage, 'Centroid', 'Area');
numberOfCircles = length(measurements);
imshow(HolesClearedImage)
end
1 comentario
Walter Roberson
el 30 de Nov. de 2015
Respuestas (0)
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!