cover irregular edges (toughs), MATLAB Image processing

2 views (last 30 days)
I am trying to fill the irregular edges of the particles. I know that these particles are in the shape of a nearly parallelogram so I want to fill them accordingly, as shown in the image.
Can someone suggest me some methods or hints to overcome this problem?
Note: I have tried convex hull and dilation. Convex hull is not suitable as it might change the shape of the particle and in dilation I need to define some parameters. I want to use some non parametric solutions.

Accepted Answer

Image Analyst
Image Analyst on 3 Oct 2014
If you're just going to take the convex hull (which changes the shape at other locations other than just that big bay), then you don't need to call edge(), imfill(), and imclose(). You can simply call bwconvhull on the binarized red channel. Here's a full demo (though the actual algorithm is only two lines):
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 36;
%===============================================================================
% Read in a color demo image.
folder = 'C:\Users\Vijay\Documents';
baseFileName = 'cap.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% 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.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 2, 1);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0, 1, 1]);
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
% greenChannel = rgbImage(:, :, 2);
% blueChannel = rgbImage(:, :, 3);
% Get the binaryImage
binaryImage = redChannel >40;
% Display the image.
subplot(2, 2, 2);
imshow(binaryImage);
axis on;
title('Binary Image', 'FontSize', fontSize);
% Take the convex hull.
chImage = bwconvhull(binaryImage,'objects');
% Display the image.
subplot(2, 2, 3);
imshow(chImage);
axis on;
title('Convex Hull Image Image', 'FontSize', fontSize);
  1 Comment
Vijay
Vijay on 3 Oct 2014
Thank you very much for the full demo. Worked for my case and now I can avoid the use of 'strel' also.

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 3 Oct 2014
You can use activecontour(), where you can put in a parameter to tell it how closely to "hug" the boundary. Attached is a demo.
  3 Comments
Vijay
Vijay on 3 Oct 2014
Thanks for your response. I'm using MATLAB 2009r and it seems that the mentioned function is not available in this version.
Sean de Wolski
Sean de Wolski on 3 Oct 2014
active countour and bwconvhull are both newer than 2009. My shrinkWrap function on the FEX implements something similar to an active contour that might help. However, I think they're overkill here and just simple morphological operations could do this.

Sign in to comment.


Sean de Wolski
Sean de Wolski on 3 Oct 2014
Edited: Sean de Wolski on 3 Oct 2014
Since you know these objects to be convex, I would use bwconvhull(...,'objects') on the binary image.
I = imread('cap.PNG');
E = edge(I(:,:,1));
BW = imfill(imclose(E,strel('disk',4)),'holes');
BWC = bwconvhull(BW,'objects');
subplot(1,2,1)
imshow(BW)
subplot(1,2,2)
imshow(BWC)
  1 Comment
Vijay
Vijay on 3 Oct 2014
Edited: Vijay on 3 Oct 2014
Thanks for your efforts. For the time I have followed the same methodology as you mentioned.
But in the future, I would like to go for some methodology to bypass the parametric value in 'strel'. Because these parameters are sometimes limitations in case of multiresolution analysis.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!