Maximum difference between each Element and neighbors in large array
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Emily Pendleton
am 25 Aug. 2017
Kommentiert: Image Analyst
am 25 Aug. 2017
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 Kommentar
Walter Roberson
am 25 Aug. 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
Akzeptierte Antwort
Image Analyst
am 25 Aug. 2017
Try this:
grayImage = imread('moon.tif');
subplot(1, 2, 1);
imshow(grayImage, []);
title('Original Image', 'FontSize', 20);
% Find local mins and maxes within sliding window.
localMaxImage = imdilate(grayImage, ones(3));
localMinImage = imerode(grayImage, ones(3));
% Find max intensity difference from center to brighter and darker images.
brighter = localMaxImage - grayImage;
darker = grayImage - localMinImage;
% Find the max difference regardless whether brighter or darker.
maxDiff = max(brighter, darker);
subplot(1, 2, 2);
imshow(maxDiff, []);
title('Max Diff Image', 'FontSize', 20);

2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!