matrix, window finding median....

조회 수: 1 (최근 30일)
Manpreet Kapoor
Manpreet Kapoor 2011년 4월 21일
Hi,
I need to make a progrqam for the following logic:
1. Consider a matrix of size 120x120. Now consider a section of 3x3 and find the median of the 3x3 section, replacing the values of the matrix to make a new matrix (of a smaller size). The new 3x3 section will be taking the next element as the central element.
2. Please see that there is a command in MATLAB, called medfilt, medfilt2, which does the same, but I need to develop a program which does this manually i.e. it first sorts our the elements in ascending or descending order and then selects the middle value as the median thereby forming a new matrix with the median values.
The program that I am building is more complex than the section which I need help on. Any help in deleveloping this program will be highly appreciated.
Thanks and Regards
Manpreet Kaur
  댓글 수: 4
Manpreet Kapoor
Manpreet Kapoor 2011년 4월 22일
I wouldn't have if I got the answer, Sorry for inconvenience.
Walter Roberson
Walter Roberson 2011년 5월 13일
duplicates http://www.mathworks.com/matlabcentral/answers/5656-program-to-find-the-median-of-the-matrix-need-to-use-for-loop

댓글을 달려면 로그인하십시오.

답변 (3개)

Sean de Wolski
Sean de Wolski 2011년 4월 21일
doc blkproc
doc blockproc
  댓글 수: 1
Manpreet Kapoor
Manpreet Kapoor 2011년 4월 21일
hi,
Actually I am new to MATLAB and I have already gone through this command. But I am unable to develop a program to achieve the sorting and finding median of the window elements.
I need step by step guidance to develop the above logic.
Please help.
Thanks and Regards
Manpreet Kaur

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2011년 4월 21일
Well what are the steps? First you have to sort:
doc sort
then you have to extract the middle value
xmiddle = x(floor(numel(x)/2))
If you can't figure it out from here; ask your professor because they're either failing to teach you properly, or you're sleeping during class.
  댓글 수: 3
Manpreet Kapoor
Manpreet Kapoor 2011년 4월 22일
BY the way, I need to ask one more thing, The command u gave does not select 2 values if the sequence is of even numbers. I actually need the program to find the median of the elements in the window.
Thanks and Regards
Manpreet Kaur
Sean de Wolski
Sean de Wolski 2011년 4월 22일
How are you going to replace one value with two median values in the even that it's even? Also, how can you have an even number of elements in a square window (i.e. a window with even sides centered on one pixel) It will always be odd (one per side=> 3*3=9; two per side => 5*5 = 25 etc.)
PS. A kind word of advice for learning MATLAB is to learn to use the built-in/stock functions and to read/understand the documentation related to them. This will get you much further and save time as there is no reason to reinvent the wheel.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2011년 4월 22일
variant (as in medfilt2)
x = randi(125,3);% input array
x = sort(x(:));
I = numel(x)/2;
if rem(I,1), y = x(ceil(I));
else y = sum(x(floor(I)+ [0 1]))/2; end

카테고리

Help CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by