Maximum difference between each Element and neighbors in large array
Mostrar comentarios más antiguos
I have an array (1024x1024). For each element, I want to find the difference between that element and all 8 neighboring elements. From there, I want to take the max difference and write it to a new array in that element's position.
For example, for array = [40 50 130; 20 10 30; 100 90 80] the output would be 120 in location (2,2)- maximum difference between the middle element (10) and all outer elements is 120 (130-10). This needs to be run through all elements in the 1024x1024 array. I'm not sure how to do this.
For each "center" element, I was attempting to identify neighbors (codes like "neighbor1 = array(middleElement,middleElement+1") and then subtract all 8 neighbors from the center element. I am running into some key issues: --elements on the corners/edges will need different codes because they don't have 8 neighbors;is there a way around this? --I can assign neighbors in a 3x3 by defining the location of the middle element and adding (-1, 0, 1) to the middle element's (x,y) location. I do not know the most efficient way to assign neighbors through all 1024x1024 elements.
Could anyone please help me with these issues?
1 comentario
Walter Roberson
el 25 de Ag. de 2017
This is essentially the same question but a different poster for https://www.mathworks.com/matlabcentral/answers/353974-finding-maximum-difference-between-element-and-all-neighboring-elements-in-an-arary
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
