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:



Here is a perverted 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');