Hi Abhimanyu,
You would first need to extract out the pixels that are along that boundary. To do this you must first crop out the original image using the ' imcrop ' function. Then you can convert the cropped image to binary image using the ' im2bw ' function. Once you have the binary image, you can use the ' bwboundaries ' function to obtain the boundary pixels. Following is a small code snippet that performs the aforementioned operations:
I = imread('\\path_to_image\image.jpg');
Icrop = imcrop(I);
subplot(2,2,1);
imshow(I);
title('Original Image');
subplot(2,2,2);
imshow(Icrop);
title('Cropped Image');
BW = im2bw(Icrop, graythresh(Icrop));
subplot(2,2,3);
imshow(BW);
title('Cropped BW Image');
[B,L] = bwboundaries(BW,'noholes');
subplot(2,2,4);
imshow(L);
title('Crop Image with Boundaries Detected');
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2)
end
You can then fit the boundary pixels to a polynomial using a curve fitting toolbox function that suits your use case.
I hope this helps.
- Rohit