Sliding window minimum and maximum filter
조회 수: 83 (최근 30일)
이전 댓글 표시
I'm trying to apply a sliding window minimum and maximum filter to an image of a certain window size. Actually, I'm trying to find the optimum window size for it. But I really haven't gotten the hang of it. I presume that I should be using blockproc to implement the sliding window, but not really sure how to find the maximum and minimum filter. As to the implementation itself, should I use loops to slide the window across the entire area of the image ?
댓글 수: 5
Image Analyst
2012년 12월 1일
From the description "A two-element vector, [V H], specifying the amount of border pixels to add to each block. The function adds V rows above and below each block and H columns left and right of each block." it looks like you'd have a windowSize of 1 so that it moves over in jumps of 1 pixel each time, but the 'BorderSize' would be half your window width so that it includes more than just the one pixel it's centered on. So if you wanted a 5 by 5 window, you'd set a windowSize of 1 and a BorderSize of 2. I think - I haven't tried it.
채택된 답변
Image Analyst
2012년 9월 29일
If you have the Image Processing Toolbox, you're in luck!. The sliding max filter is called imdilate() and the sliding min filter is imerode(). These are called "morphological operations." No loops needed:
localMinImage = imerode(grayImage, true(3));
localMaxImage = imdilate(grayImage, true(3));
댓글 수: 17
Matt J
2014년 4월 28일
Padding doesn't require the IP toolbox, e.g.,
p=2; %padding
Apad=zeros(size(A)+2*p,class(A));
Apad(p+1:end-p,p+1:end-p)=A;
Image Analyst
2014년 4월 28일
What do you mean by shift? As long as the window size is odd, e.g. 3 or 5, there will be no shift. If the window size is even, e.g. 2 or 4, then there will be a half pixel shift.
추가 답변 (4개)
Matt J
2012년 9월 29일
편집: per isakson
2014년 10월 25일
I would just use a for-loop to do 2 separable passes. BLOCKPROC can't take advantage of the separable nature of the max/min filter:
A=rand(100);
window=3;
[m,n]=size(A);
B=A;
for ii=1:m+1-window
B(ii,:)=max(A(ii:ii+window-1,:),[],1);
end
for ii=1:n+1-window
B(:,ii)=max(B(:,ii:ii+window-1),[],2);
end
댓글 수: 1
Royi Avital
2014년 4월 23일
This is nice and fast. Yet it shift the matrix to the right.
How would replicate the results of `imerode` or `imdilate` with Image Processing Toolbox (no `padaaray`) most efficiently?
Thaks.
Royi Avital
2014년 4월 23일
I would use:
localMaxImage = colfilt(inputImage, [winLength winLength], 'sliding', @max);
localMinImage = colfilt(inputImage, [winLength winLength], 'sliding', @min);
Though it is still requires patience. I wonder what would be the fastest way to do so without Image Processing Toolbox.
댓글 수: 0
tilak tenneti
2014년 10월 24일
편집: per isakson
2014년 10월 25일
i want to apply a sliding window minimum filter on input image I and obtain Imin and also apply sliding window maximum filter on Imin to obtain Imax : the following is code
N=1;
Imin=ordfilt2(I, 1, true(N));
N=10;
Imax = ordfilt2(Imin, N*N, true(N));
here i assume N as window size... but i am confused as how should i take N for minimum filter and again N for maximum filter?
댓글 수: 0
Dan
2017년 6월 19일
function [minVals,maxVals] = minmaxfilt1(vector,nhoodSz)
vector = vector(:);
if nhoodSz < 3 || ~floor(mod(nhoodSz,2))
error('nhoodSz must be odd scalar');
end
minVals = min(conv2(vector,eye(nhoodSz)),[],2);
maxVals = max(conv2(vector,eye(nhoodSz)),[],2);
minVals = minVals(((nhoodSz-1)/2)+1: end- ((nhoodSz-1)/2));
maxVals = maxVals(((nhoodSz-1)/2)+1: end - ((nhoodSz-1)/2));
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!