필터 지우기
필터 지우기

How do I reverse the convexhull?

조회 수: 1 (최근 30일)
Jeen Xavier
Jeen Xavier 2020년 10월 29일
답변: Image Analyst 2020년 10월 29일
Hi, I have the following code where I read the image file and apply the 'bwconvhull' method to it is working fine. After this process what I have done is rotated the image to a certain angle and cropped the object. My next step is to reverse the 'bwconvhull' and bring it back its to orignal image state (greyscale). How would I do this?
f = imread('image-001.bmp'); %read the image file
% Convert the image to a gray scale image
rgb = rgb2gray(f);
BW1 = edge(BW1,'canny');
CH = bwconvhull(BW1, 'union'); %applied the bwconvhull
L = bwlabel(CH,4);
% >>>>TO ROTATE THE IMAGE <<<<<<<<<<
% Create 3-by-3 transformation matrix
alpha = 176.01;
T = [cos(alpha) sin(alpha) 0;
-sin(alpha) cos(alpha) 0;
0 0 1]
% Create TFORM structure
tform = maketform('affine', T)
% Apply the transform on the input image
g = imtransform(BW1, tform);
%>>>>>>>>>>>>> <<<<<<<<<<<<<<<<<<<<<<<
%>>>>> CROP THE IMAGE <<<<
crop_image = imcrop(g,[107.5 77.5 625 404]);
% imshow(crop_image)
% At this stage I have got the desired image now I want to convert the bwconvhull back to its original gray scale image form
  댓글 수: 1
Rik
Rik 2020년 10월 29일
Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue. Your current code assigns a gray scale image to a variable named rgb and the next line uses a variable that did not previously exist. I suspect that is actually the source of your issue, otherwise I don't see what you want.

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

답변 (1개)

Image Analyst
Image Analyst 2020년 10월 29일
If all you have is a convex hull, there is no way to get the original shape. For example, a polygon or square could hold an infinite number of shapes inside and still have that same convex hull.
If you want the original, you'll have to save the original. Don't call clear to blow away the original variable and you should be fine.

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by