If I understood correctly what your goal is, you can do something like that:
close all;
figure(1);
subplot(2,2,1);
I = imread('shape.jpg');
imshow(I);
title('Original');
subplot(2,2,2);
BW = im2bw(I, 0.5);
BW = imcomplement(BW);
imshow(BW);
title('Binary');
subplot(2,2,3);
CH_objects = bwconvhull(BW,'objects');
imshow(CH_objects);
title('Objects Convex Hull');
figure(2);
[r,c]=find(CH_objects);
CH=convhull(r,c);
plot(r(CH),c(CH),'*-');
figure(3);
[r2,c2]=find(BW);
CH2=convhull(r2,c2);
plot(r2(CH2),c2(CH2),'*-');
Let's see what this code does in more detail.
For the sake of clarity I plotted the final plots in figure(2)
and figure(3)
, so the subplot()
does not change.
However on CH_objects
, we use find()
to estrapolate the coordinates (rows r1
and columns c1
) of all the white points. On these points we perform the convex hull and the indices of the convex hull points are returned in CH1
. Now in figure(2)
we plot the coordinates of such points where each point is marked with a star *
, along with the normal lines that connect such points.
Also, you can do the very same thing but starting from the BW image and not from CH_objects
. So you open a third figure and repeat the very same procedure, but starting from BW
instead.
In this case figure(1)
will return (as in your case)
whereas figure(2)
will return
and finally figure(3)
will return
Obviously feel free to rearrange such plot(s) in your subplot. You can choose either the first or second solution, depending on whether you want to use the 3rd (CH_objects
) or the 2nd (BW
) image as starting point.