Filter löschen
Filter löschen

Crop image without change aspect ration of original image

1 Ansicht (letzte 30 Tage)
Malan Jayanka
Malan Jayanka am 9 Okt. 2016
Kommentiert: Image Analyst am 9 Okt. 2016
I want to do these kind of conversion. Output image must be 256*256 pixel. I want to crop image and remain the main leaf part in the output image without change the aspect ratio of original image. Is this possible in matlab?

Antworten (1)

Walter Roberson
Walter Roberson am 9 Okt. 2016
imcrop() and pass a rectangle whose width and height are 256, 256. A section that size will be extracted. The pixel sizes will not have changed, so the aspect ratio of the extracted area will be 1:1 . If you are displaying it afterwards, give the command
axis equal
or
axis image
You do not even need imcrop for this purpose: you can do it by plain array indexing
Extracted = YourImage(First_row : First_row + 255, First_column : First_column + 255, :);
  2 Kommentare
Malan Jayanka
Malan Jayanka am 9 Okt. 2016
Bearbeitet: Malan Jayanka am 9 Okt. 2016
I have used crop function but I got output like this
But I want to get whole leaf part into 256*256 region
[rgbImage,map] = imread('DSC_0001.jpg');
[heigth,width,dim] = size(rgbImage);
cropedImage = imcrop(rgbImage,map,[2000 1000 256 256]); imshow(cropedImage);
Also plz give me example how to use axis equal
Image Analyst
Image Analyst am 9 Okt. 2016
Then that portion is not 256x256 - it's bigger. So crop out a bigger portion, then use imresize() to shrink it down.
croppedImage = imcrop(rgbImage,map,[2000 1000 512 512]);
croppedImage = imresize(croppedImage, [256,256]);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by