Borrar filtros
Borrar filtros

implement imresize function

1 visualización (últimos 30 días)
성근 송
성근 송 el 27 de Sept. de 2021
Respondida: Vatsal el 22 de Feb. de 2024
I want to scale the screen via Nearest Neighbor interpolation without using imresize. The effect of the photo is adjustable. However, the resulting photo is presented in black and white. I want to express the color of the original photo as it is.
function NN = myResizeNN(picture,scale)
I=imread(picture);
a= size(I,1);
b= size(I,2);
IR = round([1:(b*scale)]./scale);
IC = round([1:(a*scale)]./scale);
output = I(:,IR);
output = output(IC,:);
figure(1); imshow(I);title('Before interpolation');
figure(2); imshow(output);title('After interpolation');
NN = [IR,IC];
end

Respuestas (1)

Vatsal
Vatsal el 22 de Feb. de 2024
Hi,
The provided function does not preserve the color information because the function currently processes only one dimension of the image. Images in MATLAB are 3D matrices, with the third dimension representing color channels (Red, Green, Blue).
Here is a modified function which preserves the color:
function NN = myResizeNN(picture, scale)
I = imread(picture);
[a, b, ~] = size(I);
IR = round([1:(b*scale)]./scale);
IC = round([1:(a*scale)]./scale);
output = zeros(length(IC), length(IR), 3, 'like', I);
for channel = 1:3
temp = I(:,:,channel);
output_temp = temp(:,IR);
output(:,:,channel) = output_temp(IC,:);
end
figure(1); imshow(I); title('Before interpolation');
figure(2); imshow(output); title('After interpolation');
NN = [IR,IC];
end
I hope this helps!

Categorías

Más información sobre 이미지 en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!