Image analysis cell segmentation

15 visualizaciones (últimos 30 días)
Domante Rabasauskaite
Domante Rabasauskaite el 25 de Jun. de 2021
Comentada: Domante Rabasauskaite el 28 de Jun. de 2021
Hey everyone,
I am doing a project on mammalian cell analysis. The first part is to segment the cells and simplify an image to black and white. The cells in the segmented image are in white but have some black parts in it still. Has anyone ever faced this problem, and could advise me on how to remove that (marked in red circle) so the end result is just a plain white cell area?
Thank you!!!
  2 comentarios
Image Analyst
Image Analyst el 25 de Jun. de 2021
Do you want to remove all white blobs interior to another blob, like in a hole, but leave the hole (with no white blobs in the hole anymore)?
Or do you want to fill the blobs with imfill(mask, 'holes') to get rid of any black holes in the blob and make them solid?
Domante Rabasauskaite
Domante Rabasauskaite el 25 de Jun. de 2021
Yeah I was wondering whether it is possible to to get rid of any black holes in the blob and make them solid white. I have achieved this result by splitting the RGB image into three layers and adjusting settings for each one of them, them summing all three layers back together and suing imfill to fill the holes:
ifilled = imfill(icomp, 'holes');
figure, imshow(ifilled);
se = strel('disk', 10);
iopenned = imopen(ifilled,se);
But it still doesn't really do it. I need to process over a hundred images they all seem to have the same issue whenever I try to processs them in this way. I was just wodering is there anything else I could try?

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 26 de Jun. de 2021
Not sure why you're masking each RGB channel separately. Why not just try the Color Thresholder to get a single mask?
Anyway, if you want to sum your 3 masks, I suggest you either And them with & or OR them with |, like
mask = maskR | maskG | maskB;
% Fill holes
mask = imfill(mask, 'holes');
Not sure that you're doing with the open, but doing that will essentially clip off little tendrils and peninsulas sticking out of the blobs. You could also blur it and threshold if you just want a smoother boundary for some reason (why?)
% Smooth mask boundaries
windowWidth = 21;
kernel = ones(windowWidth) / windowWidth^2;
mask = conv2(double(mask), kernel, 'same') > 0.5;
  6 comentarios
Image Analyst
Image Analyst el 26 de Jun. de 2021
OK, try this:
% Demo by Image Analyst, June, 2021.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
fprintf('Beginning to run %s.m ...\n', mfilename);
%-----------------------------------------------------------------------------------------------------------------------------------
% Read in image.
folder = [];
baseFileName = 'image.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~isfile(fullFileName)
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
fullFileName = fullFileNameOnSearchPath;
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display the test image full size.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis('on', 'image');
caption = sprintf('Original Image : "%s"', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
hFig1 = gcf;
hFig1.Units = 'Normalized';
hFig1.WindowState = 'maximized';
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
hFig1.Name = 'Demo by Image Analyst';
%--------------------------------------------------------------------------------------------------------
% Mask the image
[mask, maskedRGBImage] = createMask(rgbImage);
% Get an initial distribution of areas so we can see how small they are.
props = regionprops(mask, 'Area');
allAreas = sort([props.Area])
subplot(2, 2, 2);
histogram(allAreas);
grid on;
title('Initial Area Distribution', 'FontSize', fontSize);
% Fill holes.
mask = imfill(mask, 'holes');
% Get rid of blobs less than a specifed area.
minAllowableAreaInPixels = 50;
mask = bwareaopen(mask, minAllowableAreaInPixels);
% Display the image.
subplot(2, 2, 3);
imshow(mask, []);
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Make measurements.
props = regionprops(mask, 'BoundingBox', 'Area');
allAreas = sort([props.Area])
subplot(2, 2, 4);
histogram(allAreas);
grid on;
title('Final Area Distribution', 'FontSize', fontSize);
fprintf('Done running %s.m\n', mfilename);
%==============================================================================================
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 26-Jun-2021
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.007;
channel1Max = 0.291;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.530;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.498;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
Domante Rabasauskaite
Domante Rabasauskaite el 28 de Jun. de 2021
Thank you so much !!!!!!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by