Median filter without medfilt2

18 ビュー (過去 30 日間)
Franzi
Franzi 2020 年 6 月 7 日
コメント済み: Rena Berman 2020 年 10 月 12 日
Hello everyone,
I have to implement the median filter for a gray-scale picture and a variable window(for example 3x3, 5x5, 9x9, etc) without the built in function medfilt2. It's allowed to use median() and sort() and reshape(). In the edges where you cannot build the median, we should output the original value.
Can someone help me?
  2 件のコメント
Rik
Rik 2020 年 6 月 19 日
Question recovered from Google cache:
Hello everyone,
I have to implement the median filter for a gray-scale picture and a variable window(for example 3x3, 5x5, 9x9, etc) without the built in function medfilt2. It's allowed to use median() and sort() and reshape(). In the edges where you cannot build the median, we should output the original value.
Can someone help me?
Rena Berman
Rena Berman 2020 年 10 月 12 日
(Answers Dev) Restored edit

サインインしてコメントする。

回答 (2 件)

Matt J
Matt J 2020 年 6 月 7 日
編集済み: Matt J 2020 年 6 月 7 日
Since it's a homework assignment, I don't think you need to be computationally eficient. Just loop over all the appropriately sized sub-matrices of the image and apply median() to each... You could alos use blockproc()
  5 件のコメント
Matt J
Matt J 2020 年 6 月 7 日
編集済み: Matt J 2020 年 6 月 7 日
None that minimizes memory consumption, I don't believe. You could unfold all of the window data using a very small loop like so,
Image=rand(300); %fake image
N=3; %window size
C=cell(1,N^2);
for i=1:N
for j=1:N
C{i,j} = reshape( Image(i:end+i-N,j:end+j-N) ,[],1);
end
end
C=cell2mat(C(:).');
Now you have a matrix C whos rows are the different NxN window data. You can now conveniently operate across the rows using sort() or whatever you want.. But note that this consumes N^2 times the amount of memory as a single image:
>> whos C
Name Size Bytes Class Attributes
C 88804x9 6393888 double
Franzi
Franzi 2020 年 6 月 8 日
ok, thank you!

サインインしてコメントする。


Image Analyst
Image Analyst 2020 年 6 月 7 日
Franzi: I think I already gave you my nlfilter demo in your other question. All you had to do was change the function to do median() instead of thresholding. Here, I've attached a new m-file where I've done this easy change for you. I just replaced about 5 lines of code with a call to median - pretty easy.
  1 件のコメント
Franzi
Franzi 2020 年 6 月 8 日
ok, thank you!

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by