Image segmentation and measure segmented features

Hi all,
I want to perform image segmentation as described in the research articles in Fig 5 and 6. I have attached the figure from this article. Figure 59a) and 5(b) are the original images of the microstructure. Now I wan to perform
  1. segmentation as shown in figure 5(c) and 6(c) followed by overlaying the segmented image on originalimage.
  2. Measure te length and with of the segmented features with random line segments by calculating all line intercepts.
Thanks

Answers (1)

I didn't read the whole article and can't program it up for you but with just a quick glance it looks like they're segmenting on different hues. So you could convert to HSV color space and get different "maps" for each hue by thresholding the hue channel
hsvImage = rgb2hsv(rgbImage);
hImage = hsvImage(:, :, 1);
color1 = hImage < 0.1;
color2 = hImage >= 0.1 & hImage < 0.2;
color3 = hImage >= 0.2 & hImage < 0.3;
% etc.
If youi want to fill holes of a certain size, or remove blobs less than a certain size, you could also do that with imfill() or bwareaopen().

8 Comments

I tried to perform the oerations but, bwareaopen() is not completely remivng the blobs below certain size. Alos imfill() cannot fill all the holes.
Do i have to perform some kind of edge detection first?
How can i clearly create the boundaries for a particular hues?
as shown here
Give me the image (a) as its own image, in PNG format if possible. imfill() will fill all the holes in blobs to make them solid. Maybe you just want outlines? If so use bwperim() or bwboundaries().
Here is the attached image. Thanks!
Why is there a white frame around it? Can't you just simply give me the image itself?
sorry for the inconvenience. Here is the image without any frame.
Thanks
Try this:
% Demo by Image Analyst.
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 = 'map.png';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% 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
end
rgbImage = imread(fullFileName);
[rows, columns, numberOfColorChannels] = size(rgbImage)
% Display the image.
subplot(2, 2, 1);
imshow(rgbImage, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
caption = sprintf('Original RGB Image : "%s"\n%d rows by %d columns', baseFileName, rows, columns);
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';
hsvImage = rgb2hsv(rgbImage);
hImage = hsvImage(:, :, 1);
hueEdges = linspace(0, 1, 5)
for k = 1 : length(hueEdges) - 1
% Mask the image
mask = hImage > hueEdges(k) & hImage < hueEdges(k+1);
% Re-mask the image with the new mask.
% Mask the image using bsxfun() function to multiply the mask by each channel individually. Works for gray scale as well as RGB Color images.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
% Display the mask image.
subplot(2, 2, 2);
imshow(mask, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
caption = sprintf('Mask #%d of %d, %.2f < hue <= %.2f', k, length(hueEdges)-1, hueEdges(k), hueEdges(k+1));
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Display the masked image.
subplot(2, 2, 3);
imshow(maskedRgbImage, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
caption = sprintf('Masked Image #%d of %d, %.2f < hue <= %.2f', k, length(hueEdges)-1, hueEdges(k), hueEdges(k+1));
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Display the perimeters image.
subplot(2, 2, 4);
perimImage = bwperim(mask);
imshow(perimImage, []);
axis('on', 'image');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
caption = sprintf('Region Perimeters');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
if k < length(hueEdges) - 1
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit', 'IgnoreCase', true)
return; % or break or continue.
end
end
end
msgbox('Done!');
Thanks @Image Analyst for the answere. I am wondering, how to determine the segmented feature dimensions here. I also tried to do segmentation, which looks promising too. The images are attached. Did you considered to calculate the length and width of the segmented feature?
You can get the dimensions using regionprops()
props = regionprops(mask, 'BoundingBox');
and/or bwferet().

Sign in to comment.

Categories

Products

Release

R2020b

Asked:

on 12 Oct 2021

Commented:

on 18 Oct 2021

Community Treasure Hunt

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

Start Hunting!