Matlab image spatial resolution, change pixel

 Respuesta aceptada

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

Más respuestas (2)

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 comentarios

akevg akevg
akevg akevg el 19 de Mzo. de 2022
thank you so much . it worked for me
Voss
Voss el 19 de Mzo. de 2022
Since it worked, do you mind accepting the answer? I appreciate it!
Image Analyst
Image Analyst el 19 de Mzo. de 2022
Editada: Image Analyst el 19 de Mzo. de 2022
@akevg akevg Note that the output image size is different than the original. With my code below, the image size is the same, it's just blockier looking. Do you want the output image size to be the same or smaller?
akevg akevg
akevg akevg el 19 de Mzo. de 2022
Editada: akevg akevg el 19 de Mzo. de 2022
@Image Analyst ı need same size
akevg akevg
akevg akevg el 19 de Mzo. de 2022
@_ ı accepted now. thanks
Image Analyst
Image Analyst el 19 de Mzo. de 2022
Editada: Image Analyst el 19 de Mzo. de 2022
Then you accepted the wrong answer. Watch this:
im = imread('peppers.png');
for ii = 1:6
subplot(2,3,ii);
outputImage = imresize(im,2^-(ii-1));
imshow(outputImage);
axis('on', 'image')
[rows, columns, numColors] = size(outputImage)
caption = sprintf('%d rows by %d columns', rows, columns);
title(caption)
end
rows = 384
columns = 512
numColors = 3
rows = 192
columns = 256
numColors = 3
rows = 96
columns = 128
numColors = 3
rows = 48
columns = 64
numColors = 3
rows = 24
columns = 32
numColors = 3
rows = 12
columns = 16
numColors = 3
Voss
Voss el 19 de Mzo. de 2022
I appreciate that you accepted my answer. However, if you want the same image size, go with @Image Analyst's answer and accept it instead.
akevg akevg
akevg akevg el 19 de Mzo. de 2022
@Image Analyst ı fixed thanks
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.

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 19 de Mzo. de 2022

0 votos

Use blockproc(). Solution attached.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Mzo. de 2022

Comentada:

DGM
el 20 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by