Effacer les filtres
Effacer les filtres

Finding the largest difference between any two pixels within a set of 5 contiguous pixels

1 vue (au cours des 30 derniers jours)
I have a matrix of 22 x 22 cells each containing a number. For a given cell, I need to find the largest difference between any two cells within a set of five contiguous pixels (ie. that cell and the one above, below, left and right of it). I then need to step forward one cell from the original cell and again analyse the next set of five cells, and repeat this for every column in the matrix.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Mai 2017
Use imdilate() with [0 1 0; 1 1 1; 0 1 0] to get the largest value, and imerode() with the same structuring element to get the smallest value, and subtract.
imdilate() corresponds to maximum over the selected pixels, and imerode() corresponds to minimum over the selected pixels.
  5 commentaires
mcl1993
mcl1993 le 9 Mai 2017
Thanks! The first part worked perfectly
Walter Roberson
Walter Roberson le 9 Mai 2017
The last line there, the reference to pixel_diff is a reference to the computation of the short version with imerode and imdilate, and the isequal() is just there to prove that the computations come out the same, to give evidence that the imerode / imdilate version can be trusted.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by