如何在不使用Matlab Imresize函数的情况下在Matlab中放大图像

时间:2019-03-05 18:04:45

标签: matlab

enter image description here我没有得到正确的结果,请分享您的代码

enter code here
a=imread('rice.png')
[rows,columns]=size(a);
i=1; j=1;
c=zeros(rows*4,columns);
for x=1:2;rows
for y=1:2:columns
c(i,j)=a(x,y);
j=j+1;
end
i=i+1;
j=1;
end
figure,imshow(a);
figure,imshow(c/255);
figure,imagesc(c),colormap(gray);

我正在使用此代码,但未给我适当的结果

1 个答案:

答案 0 :(得分:-1)

您应该检查原始图像的类型,并需要创建相同类型的图像。以下代码将帮助您理解扩展图像的逻辑。 假设您的图片的(1,1)像素值为128,在这里,我们将该值写入(1,1),(1,2),(2,1),(2,2)像素。

clear;clc;close all;
A=imread('rice.png'); % read the image
[rows, columns]=size(A); % get size of the image
m=2;      % Expanding ratio (you can change that value to whatever you want)
newA=zeros(rows*2, columns*2,'uint8'); %new created image should be in same
for i=1:columns                        %type with original image.
    for j=1:rows                       
        newA(i*m,j*m)=A(i,j);          % Writing pixel values on (2,2),(2,4),(4,2),(4,4),...
        newA((i*m)-1,(j*m)-1)=A(i,j);  % Writing pixel values on (1,1),(1,3),(3,1),(3,3),...
        newA((i*m),(j*m)-1)=A(i,j);    % Writing pixel values on (2,1),(2,3),(4,1),(4,3),...
        newA((i*m)-1,(j*m))=A(i,j);    % Writing pixel values on (1,2),(1,4),(3,2),(3,4),...
    end
end
相关问题