Copy image using Rect() and copyTo()

asked 2016-06-08 09:29:22 -0600

VanGog gravatar image

I followed the tutorial about dft and it worked. But I tried to remake it to a class. Small changes I did. In the tutorial the are the square if images swapped and I do not want them to be swapped. I have changed the names of variables and this is what I have:

cv::Mat tl(logScaled, Rect(0, 0, half_width, half_height)); // Top-Left - Create a ROI per quadrant
cv::Mat tr(logScaled, Rect(cx, 0, half_width, half_height)); // Top-Right
cv::Mat bl(logScaled, Rect(0, cy, half_width, half_height)); // Bottom-Left
cv::Mat br(logScaled, Rect(cx, cy, half_width, half_height)); // Bottom-Right
tl.copyTo(Images[file_no]);
tr.copyTo(Images[file_no]);
bl.copyTo(Images[file_no]);
br.copyTo(Images[file_no]);
cv::normalize(Images[file_no], Images[file_no], 0, 1, NORM_MINMAX); 
cv::imshow("spectrum magnitude", Images[file_no]);
cv::waitKey();

Only 1/4 of the image is displayed so I think it is the top left (or bottom right?) square. How to complete this successfully to copy all the 4 squares/images to the image? Images[file_no] keeps the original image untill I copy the squares onto it. It looks like the header is overwritten but how to solve it?

edit retag flag offensive close merge delete

Comments

Not too sure about the purpose of these lines. Why do you split logScaled in 4 pieces if you then want to join the very same 4 pieces to reconstruct the image? Your problem has an easy solution, but I don't think it is even needed

LorenaGdL gravatar imageLorenaGdL ( 2016-06-08 10:34:23 -0600 )edit

@LorenaGdL Thanks for your answer. Good idea. I skipped those splitting and normalized the image and now it fits to the original size. Still, I am interested why the solution in tutorial works and mine does not. It seems there are exactly same approaches, except I avoided swapping those squares.

VanGog gravatar imageVanGog ( 2016-06-08 11:05:59 -0600 )edit

@VanGog please, link the tutorial

LorenaGdL gravatar imageLorenaGdL ( 2016-06-08 11:46:30 -0600 )edit