image=imread('Tiger.jpg');
%figure,imshow(uint8(image)),title('Before applying Median Filter');
[rows, cols]=size(image);
B=zeros(rows, cols);
for rowNo=2:rows-1
for colNo=2:cols-1
K=image(rowNo-1:rowNo+1,colNo-1:colNo+1);
B(rows,cols)=median(K);
end
end
figure,imshow(uint8(B)),title('After applying Median Filter');
我想在不使用内置功能的情况下计算我的图像的中位数,但我给了我错误,任何人都可以帮我解决 错误
??? Subscripted assignment dimension mismatch.
Error in ==> Quest_2median at 18
B(rows,cols)=median(K);
答案 0 :(得分:0)
下面的代码是一个更好的实现:
image=imread('../SampleImages/cat.jpg');
%figure,imshow(uint8(image)),title('Before applying Median Filter');
image = rgb2gray(image);
image = imnoise(image,'salt & pepper');
[rows, cols]=size(image);
B=zeros(rows, cols);
for rowNo=2:rows-1
for colNo=2:cols-1
K=image(rowNo-1:rowNo+1,colNo-1:colNo+1);
K = reshape (K,1,9);
B(rowNo,colNo)=median(K);
end
end
figure,imshow(uint8(image)),title('Before applying Median Filter');
figure,imshow(uint8(B)),title('After applying Median Filter');
注释是中位函数采用向量,当你传递矩阵时,它给出一个行向量,包括每列的中位数。