Image warping based on strings with different orientations

I would like to warp an image based on strings with different orientations:

  • for each line in the input image, I can get the coordinates of the pixels on the line
  • then I would match these pixels with a perverted image so that each row becomes a column.

I would use interp2 , since I already have X , Y and Z , and I would do Xi and Yi with the coordinates obtained for each line. However, how are you:

  • to avoid creating a for loop that is indexed across the entire number of lines?
  • Make sure that each column at the output of the distorted image is the same size?
  • Sample input image with radial lines?
  • The most difficult question, in my opinion, how would you preserve the neighborhood structure, even if I use different orientations: for example, horizontal lines (lines) of the left side of the input image and radial lines for the right side?

The input image here is the bus, there is a nice drawing of circles. I could draw radial lines from the center of the bus, and I would like to get a new image whose columns are pixels from radial lines.

Here is the code that I have so far (no interp2 until I solved the problems described above).

 close all %% Image Z = imread('tire.tif'); % The corresponding mesh sz = size(Z); [X,Y] = meshgrid(1:sz(2), 1:sz(1)); %% Line lineEquation = @(c, v) (v(1)*(Xc(2))+v(2)*(Yc(1)))/norm(v); getLine = @(c, v) abs(lineEquation(c, v))<1/2; % Example c = [93, 109]; v = [2, 1]; line = getLine(c, v); %% Circle circleEquation = @(c, r) ((Xc(2)).^2+(Yc(1)).^2-r^2)/r^2; getCircle = @(c, r) abs(circleEquation(c, r))<1/r; % Example r = 24; circle = getCircle(c, r); %% Plot a sequence of line figure; for delta = -1:0.1:1 v = [0.1, delta]; line_delta = getLine(c, v); Z_line = Z; Z_line(line_delta) = 255; imagesc(Z_line); colormap('gray'); pause(0.05); end %% Plot examples figure; subplot(221); imagesc(Z); title('Image'); subplot(222); Z_line = Z; Z_line(line) = 255; imagesc(Z_line); title('Line'); subplot(223); Z_circle = Z; Z_circle(circle) = 255; imagesc(Z_circle); title('Circle'); subplot(224); % TODO title('Warped image'); colormap('gray'); 

Here are the different outputs:

Examples

Lines

Circles


Here is a perverted image: Warped image

Here is the response code:

 [ANG, RAD] = meshgrid(0:0.01:2*pi, 0:0.5:166); XI = c(2) + cos(ANG).*RAD; YI = c(1) + sin(ANG).*RAD; WARPED = interp2(X, Y, double(Z), XI, YI); WARPED(isnan(WARPED))= max(WARPED(:)); imagesc(WARPED); title('Warped image'); colormap('gray'); 
+4
source share
2 answers

Your main problem (I think) is building the XI and YI matrices needed for interp2 . You build them, realizing that in your new image the horizontal axis represents the angle of the line, and the vertical axis represents the distance from the center of the circle, so to create them:

 %% angle from 360 to 0, radius from 0 to 100 %% resulting image will be 361 x 101 pixels [ANG, RAD] = meshgrid(360:-1:0,0:100); %% I take the centre of the circle at (93, 109) Is this correct? %% From there you can create XI and YI %% from the angle and radius you have at each point XI = ones(size(ANG))*93 + cos(ANG/(2*PI)).*RAD; YI = ones(size(ANG))*109 + sin(ANG/(2*PI)).*RAD; WARPED = interp2(X,Y,Z, XI, YI) 

The output will be greatly distorted (of course), because the circle in each radius is stretched to the same length. Along the lines of distortion will be minimal. If everything goes well, and my math did not leave me, this should give you a detailed image of the tire, cut along the line from the center to the right.

+3
source

Best way: Use a second-order polynomial transform to convert all circles to strings, and then just cut the rows you want. Use the 2 Matlab cp2tform () commands with the "polyomial" and imtransform () parameters. Set the values โ€‹โ€‹of 1 for x ^ 2 and y ^ 2 inside the T transformation to create a circle and a translation to determine the center pixel of the bus.

Sorry, I am not supplying the code since I am responding with an iPhone. Postscript Check out Matlab's help on polynomial and conformal transformations. They do exactly what you need.

+2
source

All Articles