Clear Filters
Clear Filters

how to compare image size

3 views (last 30 days)
Tarik Razak
Tarik Razak on 5 Feb 2012
Answered: yanqi liu on 15 Oct 2021
hi i am trying to figure out if image is below certain size i.e.
i=imread('test.jp);
k= want to know size of the image
if (k >= [10 10])
meaning if current image is greater than 10x10 pixel
want to get this small code right.
Thanks for the reply

Answers (4)

yanqi liu
yanqi liu on 15 Oct 2021
i=imread('football.jpg');
% k= want to know size of the image
k = size(i);
if (k(1) >= 10 && k(2)>=10)
disp('size of image greater than 10 10');
end
size of image greater than 10 10

Walter Roberson
Walter Roberson on 5 Feb 2012
tk = size(i);
k = tk(1:2);
But please consider what you want to do if (say) the image is 8 x 15. Do you want to test that both dimensions are at least 10, or only that at least one dimension is at least 10, or that the "area" of the image is at least 100 ?

Image Analyst
Image Analyst on 6 Feb 2012
imageArray = imread('test.jpg');
[rows columns numberOfColorChannels] = size(imageArray)
% Check both the number of rows AND the number of columns...
if rows >= 10 && columns >= 10
% Do stuff.
else
% Bail out.
end
% OR check the number of pixels...
if rows * columns >= 100
% Do stuff.
else
% Bail out.
end

Josep Llobet
Josep Llobet on 14 Oct 2021
Excuse me because the coments are in catalan, but matbe the next code could be useful. It is for adjust one image 1 to other smaller than this one, without any of the width or height of the image 2 would be bigger than the image 1.
You can use the next variables to probe the function
% Variables proba
imatge_resize_1 = imread("https://e00-marca.uecdn.es/assets/multimedia/imagenes/2020/09/29/16014108528580.jpg");
imshow(imatge_resize_1)
size(imatge_resize_1)
imatge_resize_2 = imread("https://estaticos-cdn.prensaiberica.es/clip/4527952d-e69e-4ddc-9b53-580205a3d3f5_16-9-aspect-ratio_default_0.jpg");
imshow(imatge_resize_2)
size(imatge_resize_2)
% function [ratio_resize] = resize_im1_im2petita(imatge_resize_1, imatge_resize_2)
% If the second image is smaller in all their borders, return the resize
% ratio (used in the function imresize) that must have the second image in
% order to adjust their borders to the size of the image 1 ones.
% INICI FUNCIO
% Imatge 1 (en teoria la més gran)
imshow(imatge_resize_1)
size_im1 = size(imatge_resize_1);
size_im1 = size_im1(1:2);
% Imatge 2 (en teoria més petita)
imshow(imatge_resize_2)
size_im2 = size(imatge_resize_2);
size_im2 = size_im2(1:2);
% Si la imatge 1 és més gran que la imatge 2 en alçada o amplada:
if size_im1(1) > size_im2(1) && size_im1(2) > size_im2(2)
dif_alsada = size_im1(1) - size_im2(1);
dif_amplada = size_im1(2) - size_im2(2);
% Diferenciem per la posicio en que la diferencia es menor, donat que
% al fer variar aquesta mai en excedirem de les proporcións máximes.
% Si l'amplada és major:
if dif_amplada > dif_alsada
ratio_resize = (dif_amplada + size_im2(2) - 2) / size_im2(2);
% Si l'alçada és major, o bé si les diferencies són iguals:
else
ratio_resize = (dif_alsada + size_im2(1) - 2) / size_im2(1);
end
end
% Finalment, fem resize de la imatge, i comparem, i comprovem, les mesures:
%im_resized_re = imresize(imatge_resize_2, ratio_resize);
%imshow(im_resized_re)
%size(im_resized_re)
% FINAL FUNCIO
The return of the function is then the ratio_resize variable.
You can probe it by this way:
im_resized_re = imresize(imatge_resize_2, ratio_resize);
imshow(im_resized_re)
size(im_resized_re)
Image of the examples:
then applying imresize()
Where the answers are the use of imsize()

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!