Matlab image spatial resolution, change pixel

7 ビュー (過去 30 日間)
akevg akevg
akevg akevg 2022 年 3 月 19 日
コメント済み: DGM 2022 年 3 月 20 日
Hi, how can ı change 8 bit image's pixel numbers like these? Help please

採用された回答

Image Analyst
Image Analyst 2022 年 3 月 19 日
Try this. It will make sure the output image is exactly the same size as the input image.
inputImage = imread('peppers.png');
[inputRows, inputColumns, numColors] = size(inputImage)
inputRows = 384
inputColumns = 512
numColors = 3
for ii = 1:6
subplot(2,3,ii);
outputImage = imresize(inputImage,2^-(ii-1));
[rows, columns, numColors] = size(outputImage);
fprintf('After resizing once it is %d rows by %d columns\n', rows, columns);
% Resize output image again to match the input.
outputImage = imresize(outputImage, [inputRows, inputColumns], 'nearest');
% Update size.
[rows, columns, numColors] = size(outputImage);
fprintf(' After resizing twice it is again %d rows by %d columns\n', rows, columns);
imshow(outputImage);
% Show title with new size.
caption = sprintf('%d rows by %d columns', rows, columns);
axis('on', 'image')
title(caption)
end
After resizing once it is 384 rows by 512 columns
After resizing twice it is again 384 rows by 512 columns
After resizing once it is 192 rows by 256 columns
After resizing twice it is again 384 rows by 512 columns
After resizing once it is 96 rows by 128 columns
After resizing twice it is again 384 rows by 512 columns
After resizing once it is 48 rows by 64 columns
After resizing twice it is again 384 rows by 512 columns
After resizing once it is 24 rows by 32 columns
After resizing twice it is again 384 rows by 512 columns
After resizing once it is 12 rows by 16 columns
After resizing twice it is again 384 rows by 512 columns

その他の回答 (2 件)

Voss
Voss 2022 年 3 月 19 日
You can try imresize()
im = imread('image_1.png');
for ii = 1:6
subplot(2,3,ii);
imshow(imresize(im,2^-(ii-1)));
end
  9 件のコメント
akevg akevg
akevg akevg 2022 年 3 月 19 日
@Image Analyst ı fixed thanks
DGM
DGM 2022 年 3 月 20 日
Or you could just do
inpict = imread('peppers.png');
k = 16;
outpict = imresize(imresize(inpict,1/k,'bilinear'),k,'nearest');
imshow(outpict)
[size(inpict); size(outpict)]
ans = 2×3
384 512 3 384 512 3
Which is far simpler and much faster than using blockproc() for any moderately large image.
Of course, it depends how much control one wants over exactly which pixels are contributing to each block and how exactly they're being weighted. I'm assuming that the goal here has no technical requirements, as none were given.

サインインしてコメントする。


Image Analyst
Image Analyst 2022 年 3 月 19 日
Use blockproc(). Solution attached.
  1 件のコメント
akevg akevg
akevg akevg 2022 年 3 月 19 日
thank you so much

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by