我只想從下面的圖像中刪除白細胞並保留紅細胞。在Matlab中做到這一點的最好方法是什麼? 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 ');
這是我沒有,但它並不適用於所有圖像的工作,有什麼辦法解決呢?
我有一個以上的圖像,我不t想要手動執行,我想輸入圖像,輸出將進入另一個處理步驟和計數,你能幫助我嗎? –
我添加了允許您自動加載並保存多個圖像的代碼。 – Pieter12345
我不想保存它們,我只想提取紅血細胞並計數它們 –