Dynamically setting a 'targetSize' for centerCropWindow2d()
이전 댓글 표시
Following the example from the documentation page of the centerCropWindow2d function, I am trying to dynamically crop an image based on a 'scale' value that is set by the user. In the end, this code would be used in a loop that would scale an image at different increments, and compare the landmarks between them using feature detection and extraction methods.
I wrote some test code to try and isolate 1 instance of this user-specified image cropping,
file = 'frameCropped000001.png';
image = imread(file);
scale = 1.5;
scaled_width = scale * 900;
scaled_height = scale * 635;
target_size = [scaled_width scaled_height];
scale_window = centerCropWindow2d(size(image), target_size);
image2 = imcrop(image, scale_window);
figure;
imshow(image);
figure;
imshow(image2);
but I am met with this error:
Error using centerCropWindow2d (line 30)
Expected input to be integer-valued.
Error in testRIA (line 20)
scale_window = centerCropWindow2d(size(image), target_size);
Is there no way to do use this function the way I explained above? If not, what's the easiest way to "scale" an image around its center point [that is, if I scale it by 0.5, the image stays the same size but is zoomed in by 2x]?
Thank you in advance.
답변 (1개)
Is there no way to do use this function the way I explained above?
scale = 1.5
scaled_width = scale * 900
scaled_height = scale * 635
You are asking the function to produce an output that is 952 1/2 pixels high, but MATLAB has no way to represent storing half of a pixel. You need to floor() or ceil() the values, depending whether you want 952 or 953 pixels for the result.
카테고리
도움말 센터 및 File Exchange에서 Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!