简体   繁体   中英

image size comparison in matlab

I have two images A and B . I want to compare the size of the two images.

if A>B 
then 
    A=A; and B=B; 
else
    swap them

How can I do this in MATLAB? Any kind of help will be appreciated.

You can use numel to find the number of pixels in an image. Eg for a 16 x 16 image, numel will return 256 .

% If image A is smaller or equal as image B, swap the two images
if numel(A) <= numel(b)
    tmp = A;
    A = B;
    B = tmp;
    clear('tmp');
end

This only looks at the total number of pixels in each image. If you want to take the shape into account, you can use the size function to get the width and height of the image:

[height,width] = size(image)

Then you'd have to think of some logic, whether to swap or not: what if a is wider, but less high, and so on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM