Fill Holes in a Binary Image without using imfill()
2 views (last 30 days)
Show older comments
Develop a Matlab GUI that allows the users to fill holes in the binary image by clicking inside the hole with mouse.
Following are specific requirements:
- Your GUI must provide a button that allows the user to browse and select a binary image, and then show the selected binary image on axes.
- When the user clicks inside the image on GUI, you must use the position of mouse click as the starting point to implement the ‘Hole Filling’ algorithm discussed in class.
- You can use function ginput to read x and y coordinates of mouse click.
- You can use function imdilate to implement the morphological dilation operation.
- You can use function imcomplement to find the complement of a binary image.
- You must show the result image (with filled hole) on GUI.
- You can use the images provided with the assignment to test your algorithm.
0 Comments
Answers (1)
Image Analyst
on 24 Apr 2022
OK. Good luck. I'm confident you can do it. I don't believe imdilate() or imcomplement() will be needed. For the current pixel you're on, simply set it's value to true.
% Get initial point that user clicked on.
[x, y] = ginput(1);
row = y;
col = x;
if binaryImage(row, col)
% If they clicked on part of the image that is already filled, warn them.
warningMessage = sprintf('Please click on a black hole, not a white blob!');
uiwait(warndlg(warningMessage))
return;
end
% Now enter the loop that is your algorithm to change row and col.
% Fill the pixel as row, column.
binaryImage(row, col) = true;
Just do your algorithm to change row and column.
VERY IMPORTANT: don't mixup (x,y) with (row, column). Matrices are indexed (row, column), NOT (x,y). If you want to use the x,y terminology you have to index your matrix as (y, x).
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!