Finding sub-matrices maxima
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear community,
I am looking for an efficient method to find local maxima within a large matrix.
For now, to do so I divide the matrix into rectangle sub-matrices of size delta_X and delta_Y.
Then I run a loop for each entire rectangle computed and I search the maxima with find function.
Finally to find the index of the maxima in the whole matrix I add the index found with find function to the position of the rectangle (i.e. loop parameter).
The duration of this computation is about 0.05 seconds for a (small) 512*155 matrix. My long-term objective would be to use it with really really larger matrices but I fear its computational time.
Would you have any idea to make it faster ?
I tried imdilate function but unfortunately it does not provides a real control of maxima density.
Here is my code :
% delta_Y = 100 ; %vertical size of sub-matrix
delta_X = 200 ; %horizontal size of sub-matrix
%MAT is the large Matrix
am_rect_X = floor(size(MAT,2)/delta_X) ; %amount of horizontal entire rectangle that fit in the large matrix
am_rect_Y = floor(size(MAT,1)/delta_Y) ; %amount of vertical entire rectangle that fit in the large matrix
recta = zeros(delta_Y,delta_X) ; %sub-matrix initialization
amount_max = am_rect_X*am_rect_Y ; %amount of sub-matrices that fit in the large matrix, i.e. amount of maxima that will be computed
row = zeros(amount_max,1) ; %array initialization, to save the vertical index of each maximum in the large matrix
col = zeros(amount_max,1) ; %array initialization, to save the horizontal index of each maximum in the large matrix
count = 0 ;
for i = 1 : am_rect_X %for each entire horizontal rectangle
for j = 1 : am_rect_Y %for each entire vertical rectangle
recta = MAT(1+(j-1)*delta_Y:j*delta_Y,1+(i-1)*delta_X:i*delta_X) ; %get the desired sub-matrix
[kmaxrecY,kmaxrefX] = find(recta==max(max(recta))) ; %find maxima indexes in the sub-matrix
count = count + 1 ;
row(count) = kmaxrecY + (j-1)*delta_Y ; %save the row position of the maxima in the large matrix
col(count) = kmaxrefX + (i-1)*delta_X ; %save the column position of the maxima in the large matrix
end
end
Thanks for your help
0 Commenti
Risposte (2)
Image Analyst
il 18 Dic 2017
If you have the Image Processing Toolbox, the local max is found using either imdilate() or imregionalmax(), depending on what you want. imdilate() gives an output image where each pixel value is the max of a window centered around the original image at that pixel. imregionalmax() gives a binary image that is "true" if that pixel is the max within a window centered at that point.
0 Commenti
Vedere anche
Categorie
Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!