imcrop() not working for certain part of image..

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

I'm convinced, that your assumption "the original matrix contains pixels in that part" is not correct. Check this explicitly - see KSSV's example.

Sign in to comment.

Answers (1)

KSSV
KSSV on 6 Jul 2018
Edited: KSSV on 6 Jul 2018
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

While resizing to an arbitrary size is not necessarily useful, checking the dimensions before cropping is the way to go.

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2017a

Asked:

on 6 Jul 2018

Commented:

Jan
on 6 Jul 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!