MATLAB: Purple colour extraction only

colorcolor segmentationcolourImage Processing Toolbox

Hi, im stuggling as how to extract only the purple colour from this image.
the result that i manage to obtain
as you can see there a thin layer of the red circle and the background turn white.
How to obtain only the purple circle and make the background still white. Thank you.
My code
>> a=imread('circles.jpg');
>> redChannel=a(:,:,1);
>> greenChannel=a(:,:,2);
>> blueChannel=a(:,:,3);
>> black=zeros(size(a,1), size(a,2));
>> mask=redChannel>200; %the mask
>> imshow(mask);
>> purpleOnly=bsxfun(@times, a, cast(~mask, 'like', a)); %extract the purple image only
>> imshow(purpleOnly)

Best Answer

Try this:
mask = imdilate(redChannel>200, true(5)); %the mask