How do we upsample a colour image by 0.25 and 0.5 without using imresize() function ???
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I wanted to upsample a colour (rgb)image by 0.25 and 0.5 without using imresize(). I tried doing it but the output is black & white. Is there any solution ???
This is my script :
%%Lena image Upsample
% Importing original Lena Colour Image
lena_q = imread('lena_quarter.tif');
% Display original Lena image
figure(4)
imshow(lena_q)
title('Original Lena Colour Image')
% Upsample the original Lena image by quarter
scale3=0.25;
lena_quarter=scale3;
lena_quarterup=lena_q(1:lena_quarter:height,1:lena_quarter:width);
figure(5)
imshow(lena_quarterup)
title('Upsizing Original image of the Lena by a quarter')
% Upsample the original Lena image by half
scale4=0.5;
lena_half=scale4;
lena_halfup=lena_q(1:lena_half:height,1:lena_half:width);
figure(6)
imshow(lena_halfup)
title('Upsizing Original image of the Lena by a half')
Thanks
0 comentarios
Respuestas (3)
Walter Roberson
el 31 de Mayo de 2017
lena_quarterup = lena_q(1:lena_quarter:height, 1:lena_quarter:width, :);
Samir Mitha
el 25 de Ag. de 2020
You may want to try using the Gridded Interpolant function
0 comentarios
DGM
el 7 de Nov. de 2021
Direct subscript indexing isn't going to work, since there are no fractional indices in an array.
lena_quarterup = lena_q(1:lena_quarter:height, 1:lena_quarter:width, :);
For simple image resizing without IPT imresize(), you can just interpolate the image just like any other data.
inpict = imread('peppers.png');
inpict = im2double(inpict);
scale = 2; % upscaling
method = 'bilinear';
% input and output size
[s1 s2 s3] = size(inpict);
s = [s1 s2 s3]; % imsize() avoids this nonsense
os0 = s(1:2)*scale;
% input coordinate space
x0 = linspace(1,s(2),s(2));
y0 = linspace(1,s(1),s(1));
[X0 Y0] = meshgrid(x0,y0);
% output coordinate space
x = linspace(1,s(2),os0(2));
y = linspace(1,s(1),os0(1));
[XX YY] = meshgrid(x,y);
% interpolate
outpict = zeros([os0 s(3)]);
for c = 1:s(3)
outpict(:,:,c) = interp2(X0,Y0,inpict(:,:,c),XX,YY,method);
end
[size(inpict); size(outpict)] % input/output geometry corresponds to scale factor
imshow(outpict)
Bear in mind that this isn't how imresize() does the task, and the results will not be identical, especially if the scale is <1. For scale <1, imresize() performs antialiasing during interpolation. No such antialiasing is implemented here.
The value of this example depends on whether you want to understand some basic interpolation tasks (e.g. for homework), or if you simply need to resize images without Image Processing Toolbox. If the latter describes your needs, consider that MIMT has imresizeFB(), which can serve as a drop-in replacement for imresize(). It still uses a different interpolation approach than imresize(), but some effort has been made to make the features and results as close as possible.
0 comentarios
Ver también
Categorías
Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!