How to fill inside of binary region?
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear Matlab Community,
I'm working on a tool which measures the fiber diameter automatically. These fibers are made from PLA (Polylactic acid). There are different weight percent of this acid. And we are using optical microscope to obtain the image.
So I'm struggling with filling the fibres. I'm making a separate post because I haven't received any reply on there. I have used suggested technique in which you would reconstruct the image based on mask and marker image. This appears to work on 90% of the images. After completing the code, we were looking to calibrate and validate the script with images of known diameter. However, this technique doesn't appear to work on this glass fiber and we would also like to make this program more robust so that one doesn't have to change any values if the diameter is in very high or low range (5 microns/15 or 10).
Sorry for making a new post, but I'd really appreciate if there is any technique like inversing the image and filling the empty region. In one book, the author uses following approach, but I'm unable to achieve part D. http://s18.postimg.org/8cjie7qpl/abc.png
Sincerely, Kev
2 Commenti
Matt Kindig
il 12 Set 2013
Modificato: Matt Kindig
il 12 Set 2013
I'm not fully sure what you are attempting to do, but I believe that imclearborder() should work for your case D.
doc imclearborder
Risposte (2)
Image Analyst
il 12 Set 2013
Try tophat and bottomhat filters:
clc;
format compact
close all;
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = 'D:\Temporary stuff\';
baseFileName = 'WIYx0.jpg.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = grayImage(:, :, 2); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
se = strel('Octagon', 3);
th = imtophat(grayImage, se);
% Display the image.
subplot(2, 2, 2);
imshow(th, []);
title('Top Hat Image', 'FontSize', fontSize);
bh = imbothat(grayImage, se);
% Display the image.
subplot(2, 2, 3);
imshow(bh, []);
title('Bottom Hat Image', 'FontSize', fontSize);
out = uint8((double(th)+double(bh))/2);
% Display the image.
subplot(2, 2, 4);
imshow(out, []);
title('Output Image', 'FontSize', fontSize);
3 Commenti
Image Analyst
il 20 Set 2013
Did you code it up? If so, attach your program and your image with larger fibers. Click the paper clip icon. I can't get to dropbox from within my company - they banned it.
Ashish Uthama
il 14 Ott 2013
Modificato: Ashish Uthama
il 14 Ott 2013
How about connected component analysis? Use regionprops to obtain properties of each of the connected components (i.e areas of white surrounded by black). The 'Eccentricity' stat looks promising in differentiating 'line like' vs 'blob like'.
A quick attempt:
im = imread('/tmp/t.png');
imtool(im);
bw = all(im,3);
imshow(bw);
Obtain all stats for the connected components
stats = regionprops(bw,'all');
% There ought to be something 'different' about the inside of the tubes.
% 'Eccentricity' seems promising from the description in the doc.
eThresh = 0.99; %higher => more 'line' like
lineStats = stats([stats.Eccentricity]>eThresh);
%%Fill up the line like regions
bwFilled = bw;
lineLocations = {lineStats.PixelIdxList};
lineLocations = cell2mat(lineLocations');
bwFilled(lineLocations) = false;
imshowpair(bw, bwFilled);
As you can see, this is not perfect. Maybe you could come up with your own stat based on the pixel list of the connected component to better identify regions 'inside' the tube. (There will always be an edge case where human intervention would be required - consider multiple parallel tubes with the spacing between them being equal to the tube thickness).
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!