imcrop() not working for certain part of image..
Show older comments
I'm trying to crop certain small portion of image using the below code..
z=imread('lighthouse.png');
imc1 = imcrop( z, [630 470 7 7 ] );
disp (imc1);
But, it ended up with a empty matrix.. Even though the original matrix contains pixels in that part... (It works good for images with low dimensions... but working with high dimensional images causes some error..)
1 Comment
Jan
on 6 Jul 2018
I'm convinced, that your assumption "the original matrix contains pixels in that part" is not correct. Check this explicitly - see KSSV's example.
Answers (1)
Dimensions of your image are less then (630,470) which you have specified. YOu have to resize the image to crop to the given locations.
z=imread('lighthouse.png');
[nx,ny,nz] = size(z) ;
if nx < 630 || ny < 670
fprintf('Check the dimensions of image\n') ;
fprintf('Resize the image\n')
z = imresize(z,[1000 1000]) ;
imc1 = imcrop( z, [630 470 7 7 ] );
disp (imc1);
end
1 Comment
Jan
on 6 Jul 2018
While resizing to an arbitrary size is not necessarily useful, checking the dimensions before cropping is the way to go.
Categories
Find more on Convert Image Type 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!