# How do I reverse the convexhull?

12 views (last 30 days)
Jeen Xavier on 29 Oct 2020 at 6:49
Answered: Image Analyst on 29 Oct 2020 at 14:45
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?
% 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 Comment

Rik on 29 Oct 2020 at 13:13
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.

Image Analyst on 29 Oct 2020 at 14:45
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.

### Community Treasure Hunt

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

Start Hunting!

Translated by