【发布时间】:2015-06-22 07:28:44
【问题描述】:
我只想去除下图中的白细胞并保留红细胞。在 Matlab 中执行此操作的最佳方法是什么?
format longg;
format compact;
fontSize = 16;
rgbImage = imread('E:\GP_Final\DS\CL_13-09_image2.jpg');
[rows columns numberOfColorBands] = size(rgbImage);
% imshow(rgbImage, []);
% title('Original Color Image', 'FontSize', fontSize);
hsv = rgb2hsv(rgbImage);
% figure(2),imshow(hsv);
% Display the color channels.
hueImage = hsv(:, :, 1);
saturationImage = hsv(:, :, 2);
valueImage = hsv(:, :, 3);
subplot(2, 2, 2);
imshow(hueImage, []);
title('Hue Channel', 'FontSize', fontSize);
subplot(2, 2, 3);
imshow(saturationImage, []);
title('Saturation Channel', 'FontSize', fontSize);
subplot(2, 2, 4);
imshow(valueImage, [])
title('Value Channel', 'FontSize', fontSize);
[pixelCounts values] = hist(hueImage, 500);
figure;
bar(values, pixelCounts);
title('Histogram of Hue Channel', 'FontSize', fontSize);
redPixels = hueImage > 0.3 & hueImage >0.8 & valueImage <= 0.9;
% figure(10);
% imshow(redPixels);
% title('Map of red Pixels', 'FontSize', fontSize);
saturationImage(redPixels) = saturationImage(redPixels) *3.5;
% figure(7),imshow(saturationImage);
% title('New Saturation Channel', 'FontSize', fontSize);
% Combine back to form new hsv image
hsvImage = cat(3, hueImage, saturationImage, valueImage);
% Convert back to RGB color space.
rgbImage = hsv2rgb(hsvImage);
figure(8), imshow(rgbImage);
title('RGB Image with Enhanced red', 'FontSize', fontSize);
se1 = strel('disk',1);
erodedBW = imerode(redPixels,se1);
se2 = strel('disk',2);
dilatedBW2 = imdilate(erodedBW,se2);
se3 = strel('disk',1);
openedBW = imopen(dilatedBW2,se3);
filledBW=imfill(openedBW,'holes');
figure(3), imshow(filledBW);title('after fill holes ');
bw3=bwareaopen(filledBW,80);
figure(5), imshow(bw3);title('after remove small objects ');
这是我做的,但它不适用于所有图像,有什么方法可以解决它?
【问题讨论】: