필터 지우기
필터 지우기

implement imresize function

조회 수: 1 (최근 30일)
성근 송
성근 송 2021년 9월 27일
답변: Vatsal 2024년 2월 22일
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

답변 (1개)

Vatsal
Vatsal 2024년 2월 22일
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!

카테고리

Help CenterFile Exchange에서 이미지에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!