I dont know if my question has an answer.I have an image and crop a ROI with imcrop
[cropped_image,rect]=imcrop(original_image);
I work with cicular regions so this rectangular is not working very well.I want to draw freehand the ROI i want..
I tried this but doesnt work.(I want to get similar image such as cropped_image)
cropped_image=imfreehand();
and then extract this cropped_image and continue to my analysis

 채택된 답변

Satoshi Kobayashi
Satoshi Kobayashi 2019년 2월 3일
편집: Satoshi Kobayashi 2019년 2월 3일

0 개 추천

I = imread('corn.tif',2);
imshow(I)
h = imfreehand; % Place a closed ROI by dragging and double-click on the region.
position = round(wait(h));
min_values = min(position,[],1);
max_values = max(position,[],1);
Inew = I(min_values(2):max_values(2),min_values(1):max_values(1),:);
[X1,X2] = meshgrid(1:size(Inew,2),1:size(Inew,1));
in = inpolygon(X1,X2,position(:,1)-min_values(1)+1,position(:,2)-min_values(2)+1);
in =repmat(in,1,1,size(I,3));
Inew(~in) = 0; % If I is uint
Now Inew is the rectangular cropped image. Out of ROI has been blacked out.

댓글 수: 4

DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2019년 2월 3일
This is very good but i need only the extracted image without the black....Black creates problems for further segmentation...
Satoshi Kobayashi
Satoshi Kobayashi 2019년 2월 3일
Using only the extracted image may be difficult.
The measures to be taken depend on what you would like to do (further segmentation) and what type of image (grayscale or not) you use.
You can use any color instead of black.
DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2019년 2월 3일
ok thank you very much for support!
sinjini ghosh
sinjini ghosh 2019년 11월 12일
Could you comment on what each of the command is doing, the code works, but I didnot understand the operations you used

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

추가 답변 (1개)

Image Analyst
Image Analyst 2019년 2월 3일

1 개 추천

See my attached demo. I think you'll like it a lot better than the other answer. It gives you drawing instructions, it doesn't ask you to "confirm" the shape after you draw it, it does a variety of masking options, and it does the cropping you want. Adapt as needed.
0001 Screenshot.png

댓글 수: 4

DIMITRIOS THEODOROPOULOS
DIMITRIOS THEODOROPOULOS 2019년 2월 3일
Of course!!!!
You are a master!!!
Warid Islam
Warid Islam 2019년 7월 22일
Hi @ImageAnalyst,
I tried to draw a boundary using the freehand() above. Below is the image.fh1.jpg
However, problem arises when I try to crop that specific portion of the image defined by the boundary and save it in a different file. The following error message is displayed.
Unrecognized method, property, or field 'getPosition' for class 'images.roi.Freehand'.
Error in freehand_masking_demo (line 49)
xy = hFH.getPosition;
Any suggestions would be very much appreciated. Thank you.
Image Analyst
Image Analyst 2019년 7월 23일
Warid, what version do you have?
Warid Islam
Warid Islam 2019년 7월 23일
Hi,
I use MATLAB 2019a.

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

Community Treasure Hunt

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

Start Hunting!

Translated by