Why does imwarp returns abrupt uint8 arrays on applying a Projective Transform?
Show older comments
After performing some math on a few images, I obtained Homography matrix as below:
H =
1.0e+05 *
0.0023 0.0018 -4.4192
0.0018 0.0013 -3.3300
0.0000 0.0000 -0.0105
The image that I use is of dimension 612 * 816 * 3. After using the below code, I get the warped image dimension as 2*2*3.
tform = projective2d(H')
J = imwarp(img,tform);
Can someone please help me with this.
8 Comments
Please demonstrate this with the actual input data, img.
Here is a demonstration that does not support what you say:
H= [0.0023 0.0018 -4.4192
0.0018 0.0013 -3.3300
0 0 -0.0105] * 1e5;
out=imwarp(rand(612 , 816 , 3), projective2d(H'));
whos out
Akella Kartik
on 25 Dec 2022
Matt J
on 25 Dec 2022
A screenshot will not help us. We need you to run your code here in the forum, as I have done above.
It makes no sense to compare this use of warp() to imwarp(). Warp() is for graphical texturemapping. The output K is a copy of refImage. It would be a lot more obvious if the image weren't improperly scaled for its class.
H= [0.0023 0.0018 -4.4192 % this is Z-data
0.0018 0.0013 -3.3300
0 0 -0.0105] * 1e5;
refImage = imread('peppers.png'); % this is a uint8 image
% refImage is mapped onto the surface defined by H
% image is correctly scaled for class 'double', so it actually shows up
K = warp(H, im2double(refImage)).CData;
So we can ignore warp() here. It's not relevant.
EDIT: I went ahead and ran OCR on the screenshot. I kind of had a hunch that full precision was necessary for the issue to arise.
% this is H to full precision, class double
H = [234.40055498025358815539220813662, 176.16693542091721269571280572563, -441919.76452097168657928705215454;
175.87313731614469247688248287886, 133.74617803109279634554695803672, -332998.0214978544972836971282959;
0.55541916052038531326218162575969, 0.41922221571270390505503655731445, -1050.6303467652635390550130978227];
% this is a uint8 RGB image (the class doesn't matter here)
inpict = im2uint8(rand(612,816,3));
% apply the transformation
outpict = imwarp(inpict, projective2d(H'));
size(outpict)
... and I was right. As to why that's the case, I'll defer to someone who can intuit their way around spatial transformations.
Akella Kartik
on 26 Dec 2022
DGM
on 26 Dec 2022
For spatial transformations of images, use imwarp(). For texturemapping of surfaces in a plot, use warp().
Since I've demonstrated that the issue occurs with a randomly generated image, I don't think it's necessary to use your particular image. That said, for future questions, you can attach relevant files using the paperclip button in the editor toolbar.
For this question, the issue lies in H and whether it's appropriate for the task or being handled correctly (I'm going to assume it is). Someone who is more familiar with these transformations should be able to look at H' and tell whether it's expected that the output is downscaled like this. It may not be an issue of scale, but of the outputview being inappropriate.
Akella Kartik
on 26 Dec 2022
Akella Kartik
on 26 Dec 2022
Answers (0)
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

