cover irregular edges (toughs), MATLAB Image processing

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.

 채택된 답변

Image Analyst
Image Analyst 2014년 10월 3일
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

Thank you very much for the full demo. Worked for my case and now I can avoid the use of 'strel' also.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Image Analyst
Image Analyst 2014년 10월 3일

2 개 추천

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

I love this active contour. Very handy tool
Thanks for your response. I'm using MATLAB 2009r and it seems that the mentioned function is not available in this version.
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.

댓글을 달려면 로그인하십시오.

Sean de Wolski
Sean de Wolski 2014년 10월 3일
편집: Sean de Wolski 2014년 10월 3일
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

Vijay
Vijay 2014년 10월 3일
편집: Vijay 2014년 10월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Display Image에 대해 자세히 알아보기

질문:

2014년 10월 3일

댓글:

2014년 10월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by