How to flatten an image and find dimensions?

I have a source image shown below (full size)
I want to flatten it and fit it within a circle of known diameter (say 20cm).
Below is an example that i have tried to produce in image editing software where I drew a yellow circle and skewed and resized the image to match with the circle.
Is it possible to do in matlab. I want to measure dimensions of the inner circle based on the known dimension of the outer circle.
Thanks

2 Comments

Stephen23
Stephen23 on 4 May 2026 at 14:02
Edited: Stephen23 on 4 May 2026 at 14:13
So basically you have some part of the image which you know (i.e. prior knowledge) is a circle in the real-world, and you want to skew/warp the image in such a way that it is also displayed as a circle?
How do you want to identify that circle: 1) automagically (if so, based on what properties?) or 2) by hand (e.g. a lasso) ?
Hi Stephen.
Yes, it is assumed that it is a perfect circle in real world and I want to reshape into a circle.
The only information I have is the actually measured diameter (20cm). I tried to explore using the following approach
clc
clear all
close all
RGB = imread('source_crop.jpg');
Error using imread>get_full_filename (line 637)
Unable to find file "source_crop.jpg".

Error in imread (line 395)
fullname = get_full_filename(filename);
I = im2gray(RGB);
bw = imbinarize(I,"adaptive",'ForegroundPolarity','bright','Sensitivity',0.55);
figure
imshowpair(RGB,bw,'montage')
it shows the outline as below
It shows an ellipse. I want to skew the ellips The whole image then can be skewed in a way that the ellipse becomes a circle, then i can find the thickness of the orange pipe that is bein extrided out based on the information that the external circle has diameter of 20cm.
After the circle is identified, its centroid can be found and based on that rest of the dimensions can be measured. I would not want to use any input like lasso or marking the center using click to preserve reproduceability.

Sign in to comment.

Answers (1)

Matt J
Matt J on 4 May 2026 at 14:37
Edited: Matt J on 4 May 2026 at 14:45
Find the 4 vertices of the outer ellipse (i.e., the end points of the major and minor axes). This can be done manually with drawellipse. SInce you already know the corresponding 4 points on the outer circle, you can then use fitgeotform2d to find the projective mapping between the two sets of 4 points.
You can then use the mapping obtained this way to "flatten" the entire image with imwarp. Or you could just extract boundary coordinates on the inner ellipse and transform those with transformPointsForward.

1 Comment

Thank you. I will work on this and see if I can get the results.

Sign in to comment.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products

Release

R2026a

Asked:

on 4 May 2026 at 13:46

Commented:

on 4 May 2026 at 14:47

Community Treasure Hunt

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

Start Hunting!