MATLAB: Extracting color contours and fields from images

colorhsvhsv segmentationImage Processing Toolboxkinetic perimetry

I am analyzing kinetic perimetry images. I am using hsv-based segmentation to extract the colour visual fields area (red, blue and yellow) and the red, blue and yellow contours (the isopters). I am having trouble extracting the masks of each colour field, as they are not 'compact', because of the gray lines (the axes), and I was wondering if there is something I can do (beside morphological operations after extracting the masks).
For the contours (isopters), I can't seem to find a way to extract them separately, and make them to be a continuous line. Any advice would be well-taken.
im=imread('test.jpg');
hsv=rgb2hsv(im);
h=hsv(:,:,1);
s=hsv(:,:,2);
v=hsv(:,:,3);
figure, imshow(hsv);
[x,y]=size(h);
% RED field mask
for i=1:x
for j=1:y
if((h(i,j)>0.01 & h(i,j)<0.05 | h(i,j)>0.875 ) & (s(i,j)<0.3 & s(i,j)>0.1) & v(i,j)>0.9)
mask_red(i,j)=1;
else
mask_red(i,j)=0;
end
end
end
figure, imshow(mask_red)
% YELLOW field mask
for i=1:x
for j=1:y
if((h(i,j)>0.09 & h(i,j)<0.17) & (s(i,j)<0.15 & s(i,j)>0.1) & v(i,j)>0.95)
mask_yellow(i,j)=1;
else
mask_yellow(i,j)=0;
end
end
end
figure, imshow(mask_yellow);
% BLUE field mask
for i=1:x
for j=1:y
if((h(i,j)>0.485 & h(i,j)<0.7) & (s(i,j)<0.5 & s(i,j)>0.1) & v(i,j)>0.98)
mask_blue(i,j)=1;
else
mask_blue(i,j)=0;
end
end
end
figure,imshow(mask_blue);
% RED isopter
for i=1:x
for j=1:y
if(( h(i,j)<0.0166 | h(i,j)>0.9166) & s(i,j)>0.6 & v(i,j)>0.6)
mask_red_iso(i,j)=1;
else
mask_red_iso(i,j)=0;
end
end
end
figure, imshow(mask_red_iso);
% BLUE isopter
for i=1:x
for j=1:y
if( (h(i,j)>0.57 & h(i,j)<0.7) & s(i,j)>0.6 & v(i,j)>0.3)
masck_blue_iso(i,j)=1;
else
mask_blue_iso(i,j)=0;
end
end
end
figure, imshow(mask_blue_iso);
% YELLOW isopter
for i=1:x
for j=1:y
if( (h(i,j)>0.05 & h(i,j)<0.07) & s(i,j)>0.9 & v(i,j)>0.8)
mask_yellow_iso(i,j)=1;
else
mask_yellow_iso(i,j)=0;
end
end
end
figure, imshow(mask_yellow_iso);

Best Answer

I'd use the Color Thresholder to get mask functions for the 7 or 8 colored regions and lines you want. Then I'd use imclose() to fill gaps or join nearby disconnected regions of the same color. You can also use imfill() with bwareafilt() to fill small interior holes in, say, the pink region without filling in the entire donut hole of the pink region. Not hard - give it a try.