How to segment an image of an object from it body with the presence of shadow with same or lower intensity value?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
clear all; close all; clc;
img = imread("enhancedimage.jpg");
I1 = rgb2gray(img);
figure, imshow(I1);
% imageSegmenter(I1);
% function [BW,maskedImage] = segmentImage(I1)
% %segmentImage Segment image using auto-generated code from imageSegmenter app
% % [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% % code from the imageSegmenter app. The final segmentation is returned in
% % BW, and a masked image is returned in MASKEDIMAGE.
%
% % Auto-generated by imageSegmenter app on 06-Nov-2023
% ----------------------------------------------------
% Adjust data to span data range.
X1 = imadjust(I1);
% Threshold image - manual threshold
BW = X1 > 10;
% Active contour
iterations = 10;
BW = activecontour(X1, BW, iterations, 'Chan-Vese');
% Create masked image.
maskedImage = X1;
maskedImage(~BW) = 0;
% end
figure, imshow(maskedImage);
C=~maskedImage;
figure, imshow(C);
As you can see from the figure attached, I am trying to segment a nucleus (rounded-like shape) from a cell with a presence of shadow on the cell. I have try thresholding, Otsu thresholding and circular hough Transform. The result gave the same which are including the shadow and dark background as an object. Is there a way to segment the nucleus only? I have try to control the threshold value but it did not meet the expectation.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1555322/image.jpeg)
A comparison of the grayscale image and it segmentation
0 Commenti
Risposta accettata
Image Analyst
il 29 Nov 2023
First you can ask bwareafilt to give you only blobs that fall into a certain size range (range of area in pixels).
mask = bwareafilt(mask, [minArea, maxArea]); % Get just acceptable areas.
Then you can ask regionprops to give you the circularities. From those you can distinguish roundish objects from oblong or stick-like objects. Something like
labeledImage = bwlabel(mask); % Give each blob an ID number.
props = regionprops(labeledImage, 'Circularity');
allCircs = [props.Circularity]
goodCircs = allCircs > 0.6; % Or whatever. This is a logical vector of true or false.
goodIndexes = find(goodCircs); % Convert logical vector to actual index numbers.
% Extract only the good blobs.
mask = ismember(labeledImage, goodIndexes);
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!