Downsample for 3 different scales

12 ビュー (過去 30 日間)
Christina Chatzianagnostou
Christina Chatzianagnostou 2021 年 10 月 30 日
回答済み: Dave B 2021 年 10 月 30 日
Hey, I want to downsample for 3 different scales as described below:
1/2 in the rows and 1/4 in the columns
1/4 in the rows and 1/2 in the columns
1/8 in rows and 1/8 in columns
How can I use the imresize function? For example:
downNearest=imresize(img, 1/2, 1/4, ....)

回答 (1 件)

Dave B
Dave B 2021 年 10 月 30 日
To use imresize with uneven width and height specify the target number of rows and columns:
im=imread('peppers.png');
nr = height(im);
nc = width(im);
im_2_4=imresize(im,[nr/2 nc/4]);
im_4_2=imresize(im,[nr/4 nc/2]);
im_8_8=imresize(im,[nr/8 nc/8]); % or imresize(im,1/8);
size(im)
ans = 1×3
384 512 3
size(im_2_4)
ans = 1×3
192 128 3
size(im_4_2)
ans = 1×3
96 256 3
size(im_8_8)
ans = 1×3
48 64 3
If you want to use nearest neighbor interpolation when resizing, simply append nearest to the command as follows:
imresize(im,[nr/2 nc/4],'nearest');

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by