imwarp square in rectangular array to a rectangle in same rectangular array
2 ビュー (過去 30 日間)
古いコメントを表示
Hello!
I am working with image processing and manipulation so I work mainly with arrays.
My issue is that I have a rectangular array representing an image (1920rowsx2560col) and have a square array centered within (1601rowsx1601col), any element between the square inside and the rectangle boarders is a 1. The goal is to warp the square inside to a trapezoidal shape with specific points being [187 77;2415 68;2297 1721;236 1739].
Unif is my square and has random pixel values between 50 and 170.
The error I encounter with my code (attached bellow) is the output I get which is wrong where my square warps to the top right corner (can't tell if it keeps its size but looks rectangular) and the bottom left points get changed to 0 and then the rest is unaffected.
Note that I have used the following code succesfully when warping from the bellow final_points to [0 0;2560 0;2560 1920;0 1920] (I am basicly going backwards from previously).
Any help would be greatly appreciated, thanks in adavance!
row_top_left = 159.5;
row_bottom_right = 1759.5;
column_top_left = 479.5;
column_bottom_right = 2079.5;
empty_Unif(floor(row_top_left):floor(row_bottom_right), floor(column_top_left):floor(column_bottom_right)) = Unif; %center Unif inside bigger array of 1
original_points = [row_top_left column_top_left;row_bottom_right column_top_left;row_bottom_right column_bottom_right;row_top_left column_bottom_right]; %(x,y) coordinate of 4 corners from diffusor coresponding to img, use paint to get them
final_points = [187 77;2415 68;2297 1721;236 1739]; %4 corners of the image before we cropped
image_transformation = fitgeotrans(original_points,final_points,'projective'); %describing transformation
reference_image_size = imref2d(size(empty_Unif),[1 size(empty_Unif,2)],[1 size(empty_Unif,1)]); %set new image size to be identical to orginal one
output_Unif = imwarp(full_Unif, reference_image_size, image_transformation, 'OutputView', reference_image_size); %warping image
Picture wise this more or less describes what I have, get, and want.
Have: Get: Want:
1 1 1 1 1 1 1 1 1 1 1 # # # 1 1 1 1 1 1 1
1 1 # # # 1 1 1 1 1 1 # # # 1 # # # # # 1
1 1 # # # 1 1 1 1 1 1 # # # 1 # # # # # 1
1 1 # # # 1 1 1 1 1 1 1 1 1 1 # # # # # 1
1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 件のコメント
回答 (1 件)
DGM
2024 年 10 月 2 日
I think the problem here was twofold. The input point list was flipped [y x], and the output point list was not expressed in the same sequence.
% construct the test image
% such that we have a square centered inside the frame
inpict = ones(1920,2560); % background is 1
fillvalue = 0; % foreground is 0
y1 = 159.5;
y2 = 1759.5;
x1 = 479.5;
x2 = 2079.5;
yrange = floor(y1):floor(y2);
xrange = floor(x1):floor(x2);
inpict(yrange,xrange) = fillvalue; % the constructed test image
% (x,y) coordinate of 4 corners from diffusor coresponding to img, use paint to get them
Pin = [x1 y1;
x1 y2;
x2 y2;
x2 y1];
% 4 corners of the image before we cropped
Pout = [187 77;
236 1739;
2297 1721;
2415 68];
% describing transformation
T = fitgeotrans(Pin,Pout,'projective');
ref = imref2d(size(inpict),[1 size(inpict,2)],[1 size(inpict,1)]); %set new image size to be identical to orginal one
outpict = imwarp(inpict, ref, T, 'OutputView', ref,'fillvalue',1); %warping image
imshow(outpict)
Additionally, note the use of the 'fillvalue' option to accomodate the reversed polarity.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Read, Write, and Modify Image についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!