Cut a .JPG image

Hi everybody,
i would like to cut a .JPG image. To do this i used that script but it does not run:
X=imread('C:\Users\Utente\Desktop\DSC_0183.JPG');
[columns,rows,colors]=size(X);
X2 = imcrop(X,[400, 1, rows-400, columns]);
imshow(X2)
With X=my image and X2=new image
and 400, 1=coordinates of the upper left corner of the specified rectangle
and rows-400, columns= coordinates of the bottom right corner of the specified rectangle.
In particular the image (X2) is correctly cut to the left but not to the right. How can i resolve it?
Thank you!!

Answers (1)

KSSV
KSSV on 19 Feb 2019
Select your region manually.
X=imread('C:\Users\Utente\Desktop\DSC_0183.JPG');
[columns,rows,colors]=size(X);
X2 = imcrop(X);
imshow(X2)

4 Comments

Thank you for answering,
but i need to cut images automatically.
KSSV
KSSV on 19 Feb 2019
Yes I can understand......first cut it manually..extract the exact locations and then try it using code. I suspect, you would have messed up with the locations where to cut.
I cut it manually and the X,Y rectangle coordinates are:
400, 1 (upper left corner);
2592, 1 (upper right corner);
400,2000 (bottom left corner);
2592, 2000 (bottom right corner)
How can i write the script to do this automatically?
KSSV
KSSV on 19 Feb 2019
Edited: KSSV on 19 Feb 2019
X=imread('C:\Users\Utente\Desktop\DSC_0183.JPG');
[columns,rows,colors]=size(X);
[X2,R] = imcrop(X);
imshow(X2)
X3 = imcrop(X,R);
imshow(X3)

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2018b

Asked:

on 19 Feb 2019

Edited:

on 19 Feb 2019

Community Treasure Hunt

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

Start Hunting!