How to crop image using imfreehand and save the output without connecting the boundaries

2 Ansichten (letzte 30 Tage)
I have an input Image, I want to crop the image using imfreehand with closed boundary option. Unfortunately when I create mask and save the output:
h = imfreehand('Closed',false);
output_mask = h.createMask();
the end points of the cropped region becomes a closed polygon.
This is input file
This is the required output.
I am getting this output
Thanks in advance

Antworten (2)

Matt J
Matt J am 19 Dez. 2019
Bearbeitet: Matt J am 19 Dez. 2019
I think you simply neglected to trace the full boundary of the shape. Though I traced very quickly and unneatly, the result I get below shows what you should be getting when you trace the full boundary.
  6 Kommentare
Praveen GB
Praveen GB am 20 Dez. 2019
Bearbeitet: Image Analyst am 20 Dez. 2019
Hi Matt, Thanks for the reply. I have so many such structures in a image, I want to manually crop these structures and find the edges as shown in the depicted output.
Thanks
Image Analyst
Image Analyst am 20 Dez. 2019
Your depicted desired output does not show the edges - it shows the entire, filled blob.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 19 Dez. 2019
If you want that output, why not simply binarize the image:
grayImage = imread('image.png');
if ndims(grayImage) == 3
grayImage = rgb2gray(grayImage); % Convert RGB image into gray scale.
end
subplot(1, 2, 1);
imshow(grayImage);
binaryImage = ~imbinarize(grayImage);
subplot(1, 2, 2);
imshow(binaryImage);
0000 Screenshot.png
It looks like the above image is what you said you want, so why do freehand masking?
  4 Kommentare
Praveen GB
Praveen GB am 20 Dez. 2019
This is my input input.png and I want to crop the input and get output like output.png.
Since so many structures are present in input image, I have to crop it using free hand.
Thanks
Image Analyst
Image Analyst am 20 Dez. 2019
OK, no explanation for why you need edges - I guess it's proprietary or something.
However my masking demo will allow you to mask freehand-drawn regions with optional cropping into a subimage if you want. Does it not do what you want? You can still detect edges if you feel that is definitely the best approach.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Author Block Masks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by