Maximising Pixels within Certain area of Matrix
    4 views (last 30 days)
  
       Show older comments
    
    Harry Andrews
 on 13 Jul 2018
  
    
    
    
    
    Commented: Harry Andrews
 on 13 Jul 2018
            Hi Everyone,
I'd like to loop through a matrix (128x128) and find the area (Lets say 5x5 Pixels) with the highest pixel values.
What is the best way to do this?
Thanks!
2 Comments
Accepted Answer
  Guillaume
      
      
 on 13 Jul 2018
        
      Edited: Guillaume
      
      
 on 13 Jul 2018
  
      One whose sum of pixel values is the greatest
Convolve your matrix with an array of 1 the same size as the area. The location of the maximum of the convolution is the centre of the area with the highest sum:
areasum = conv2(yourmatrix, ones(5)), 'same');
[~, idx] = max(areasum);
[centrerow, centrecol] = ind2sub(size(yourmatrix), idx)
More Answers (0)
See Also
Categories
				Find more on Logical in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!