Watershed isn't segmenting properly and why is it when I return the image as binary, only half the objects show up?

10 次查看(过去 30 天)
My project involves taking manual segmentations in an image and analyzing them in terms of shape and roundness. However I have 2 major problems. 1) the watershed segmentation doesnt completely seperate the objects from each other and in some cases segments an object into fragments. 2) when I use imbinarize to reformat the image, it only returns half the objects. Is there something in my code thats causing this and is there any way to fix it? Ive attached the original image. n19_lgdel.JPG
% Read in image into an array.
[rgbImage storedColorMap] = imread('n19_lgdel.jpg');
[rows columns numberOfColorBands] = size(rgbImage);
% Extract out the color bands from the original image
% into 3 separate 2D arrays, one for each color component.
redBand = rgbImage(:, :, 1);
greenBand = rgbImage(:, :, 2);
blueBand = rgbImage(:, :, 3);
%set thresholds levels for RGB
redThresholdLow = 125;
redThresholdHigh = 255;
greenThresholdLow = 0;
greenThresholdHigh = 122;
blueThresholdLow = 0;
blueThresholdHigh = 122;
% Now apply each color band's particular thresholds to the color band
redMask = (redBand >= redThresholdLow) & (redBand <= redThresholdHigh);
greenMask = (greenBand >= greenThresholdLow) & (greenBand <= greenThresholdHigh);
blueMask = (blueBand >= blueThresholdLow) & (blueBand <= blueThresholdHigh);
% Display the thresholded binary images.
%only used as a checkpoint
%figure,imshow(redMask, []);
%figure,imshow(greenMask, []);
%figure,imshow(blueMask, []);
% Combine the masks to find where all 3 are "true."
% Then we will have the mask of only the red parts of the image.
Objects = uint8(redMask & greenMask & blueMask);
%figure,imshow(redObjectsMask, []); %only used as a checkpoint
% Get rid of small objects.
smallestAcceptableArea=100;
Objects = uint8(bwareaopen(Objects, smallestAcceptableArea));
%figure,imshow(Objects, []); % only used as a checkpoint
% Smooth the border
structuringElement = strel('disk',1);
Objects = imclose(Objects, structuringElement);
%figure,imshow(Objects, []); %only used as a checkpoint
% Fill in any holes in the regions
Objects = uint8(imfill(Objects, 'holes'));
%figure,imshow(Objects, []); %only used as a checkpoint
%seperate mitochondria from each other - watershed segmentation is
%creating lines in objects and also not seperating all objects
bw=Objects;
D=bwdist(~bw);
figure
imshow(D,[]); %checkpoint
D=-D;
L=watershed(D);
L(~bw)=0;
A=imbinarize(L); %only gets half the image from L!!!!!
figure,imshow(A);
%function to measure area and roundness of mitochondria
data=regionprops('table',A,'Area','MajorAxisLength');
data.Roundness=4*data.Area./(pi*data.MajorAxisLength.^2);
%plot histograms for image
figure,h1=histogram(data.Area);
title('Area (in pixels) of Mitochondria');
xlabel('# of pixels');
ylabel('# of Mitochondria');
figure,h2=histogram(data.Roundness);
title('Roundness of Mitochondria');
xlabel('Roundness (%)');
ylabel('# of Mitochondria');
%calculate average area and roundness for image
avarea=mean(data.Area);
avroundness=mean(data.Roundness);

采纳的回答

Image Analyst
Image Analyst 2018-11-23
See Steve's discussion in his blog: Image Processing Blog

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by