フィルターのクリア

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 Center および File Exchange이미지 についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!