Matlab 图像的下采样问题
所以我尝试使用嵌套for循环对图像进行降采样。在这里,我有一个359x479(宽x高)的图像。我试图通过删除偶数行和列,将其降采样为180x240图像。然而,它似乎不起作用。我最终得到与输出相同的图像Matlab 图像的下采样问题,matlab,Matlab,所以我尝试使用嵌套for循环对图像进行降采样。在这里,我有一个359x479(宽x高)的图像。我试图通过删除偶数行和列,将其降采样为180x240图像。然而,它似乎不起作用。我最终得到与输出相同的图像 a=imread('w.jpg'); %input image a=im2double(a); %convert it to double r=[[1 1 1];[1 1 1];[1 1 1]]/9; % the next 3 steps done to low pass filter the
a=imread('w.jpg'); %input image
a=im2double(a); %convert it to double
r=[[1 1 1];[1 1 1];[1 1 1]]/9; % the next 3 steps done to low pass
filter the image
c=imfilter(a,r,'replicate');
imshow(c);
for i=1:359 % for rows
for j=1:479 %for columns
if(mod(i,2)~=0) %to remove even rows
if(mod(j,2)~=0) %to remove odd columns
b(i,j)=c(i,j); %if i and j are odd, the pixel value is assigned to b
end
end
end
end
figure, imshow(b);
应该得到一张180x240的图像,但仍然得到大小为359x479的相同图像。您还需要在两张图像上只分配一个像素!如果不这样做,则一半的列/行将只包含0值 因此,您需要使用:
b(ceil(i/2),ceil(j/2))=c(i,j);
其中2对应于模的值
您还可以通过简单地编写以下代码来避免使用某些循环:
b = c(1:2:259,1:2:194);
b(ceil(i/2),ceil(j/2))=c(i,j);如果我必须删除每3行和每3列,该如何修改此语句?例如,使用
ind=1:100
可以抑制每3行ind(mod(x,3)==0)=[]
,现在,您可以使用ind
索引另一个大小为100x1的向量。