MATLAB Answers

how to use crop using coordinate?

16 views (last 30 days)
reza hamzeh
reza hamzeh on 24 Jan 2020 at 18:48
Edited: Walter Roberson on 24 Jan 2020 at 22:34
hi. i want to crop the red square from this pic using coordinate. lets suppose coordinate of the top-left point of the red square is w/2 and h/2
where w and h are width and hight of the pic respectively. and width and hight of the red square are 20 pixel. this is my code but it dosent work. plz help me.
pic=imread('b.jpg');
[w, h, numberOfColorChannels] = size(pic);
I=imcrop(pic,[w*0.5 h*0.5 20 20]);
imshow(I)
black.jpg

  2 Comments

Spencer Chen
Spencer Chen on 24 Jan 2020 at 22:26
Would be great if you describe what did not work.
Rik
Rik on 24 Jan 2020 at 22:31
Also, it is probably a good idea to round your coordinates to integers.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 24 Jan 2020 at 22:33
Edited: Walter Roberson on 24 Jan 2020 at 22:34
You need
[h, w, numberOfColorChannels] = size(pic);
not
[w, h, numberOfColorChannels] = size(pic);

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.


Translated by