Curve Fitting Certain Pixels in an Image

8 visualizzazioni (ultimi 30 giorni)
Abhimanyu Choudhary
Abhimanyu Choudhary il 4 Ago 2015
Modificato: Rohit Kudva il 6 Ago 2015
Hello, I have an image, which I turned into a binary image (black and white), using the im2bw function and an automatically determined threshold. I would now like to take a certain region of the image, and fit the pixels to a polynomial. More specifically, I want to fit some of the pixels on the black and white border.I have attached an image with a yellow tracing around the portion of the image for which I would like to do this.
Does anyone know how I would go about this? Also, I would like to know if it would be possible to change the coordinate system of the curve if one can be produced? I would like it such that the origin of the polynomial lie at the red dot, or somewhere in the general area.
Thank you, and I'm excited to join this community!

Risposte (1)

Rohit Kudva
Rohit Kudva il 6 Ago 2015
Modificato: Rohit Kudva il 6 Ago 2015
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

Categorie

Scopri di più su Images in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by