just a question

조회 수: 1 (최근 30일)
Stephen
Stephen 2012년 5월 29일
let's say i have the image:
img =
[1 0 -1;
0 -1 0;
1 1 -1];
and I'd like to get the values on the 8-connected area around the center:
vals = [0 -1 0 1 0 1 1 -1];
and then get the most common and least common values, and if there are two, to pick the lowest value.
I can only thing to do:
meh = im2col(img,[3 3],'distinct');
meh(5,:) = [];
answer = mode(meh);
but i can't figure out a way to get the least common thing unless i do ~mode a bunch of times...
Any ideas? Thanks :)

채택된 답변

Image Analyst
Image Analyst 2012년 5월 29일
You could use blockproc and have the blockproc function call hist. But you know that there could be up to 8 values that are the least common. What if your 8 neighbors are 8 unique values? What do you want to do then?
  댓글 수: 5
Image Analyst
Image Analyst 2012년 5월 29일
Yes, you could do the same thing with nlfilter and it is easier to understand. Good point.
Stephen
Stephen 2012년 6월 4일
yeah, but you asked if all values were unique, what would happen. It should order from lowest to highest and return the extremes. Thanks Teja, I'll check out nlfilter

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

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by