rgbImage = imread(fullFileName);
[rows columns numberOfColorBands] = size(rgbImage);
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
medianRed = medfilt2(redChannel, [7 7]);
medianGreen = medfilt2(greenChannel, [7 7]);
medianBlue = medfilt2(blueChannel, [7 7]);
subplot(2, 2, 2);
imshow(medianRed);
title('Red Median Image', 'FontSize', fontSize);
thresholdValue = 40;
pureRed = redChannel >= thresholdValue & greenChannel < thresholdValue & blueChannel < thresholdValue;
pureGreen = redChannel < thresholdValue & greenChannel >= thresholdValue & blueChannel < thresholdValue;
pureBlue = redChannel < thresholdValue & greenChannel < thresholdValue & blueChannel >= thresholdValue;
subplot(2, 2, 3);
imshow(pureRed);
title('Red Mask Image', 'FontSize', fontSize);
redChannel(pureRed) = medianRed(pureRed);
greenChannel(pureGreen ) = medianGreen(pureGreen );
blueChannel (pureBlue ) = medianBlue(pureBlue );
rgbImageFixed = cat(3, redChannel, greenChannel, blueChannel);
subplot(2, 2, 4);
imshow(rgbImageFixed);
title('Fixed RGB Image', 'FontSize', fontSize);
Best Answer