# How to compare the intensity of the central pixel with its 8 neighboring pixel in an image? Can anyone help me with its matlab code? Also I have to save my central pixel if its intensity value is greater than other pixels.

4 visualizzazioni (ultimi 30 giorni)
kiruthika r il 9 Ago 2015
Commentato: Image Analyst il 9 Ago 2015
How to compare the intensity of the central pixel with its 8 neighboring pixel in an image? Can anyone help me with its matlab code? Also I have to save my central pixel if its intensity value is greater than other pixels.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

David Young il 9 Ago 2015
Some of the answers here should help.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Image Analyst il 9 Ago 2015
Except that those answers were written before the built-in function came out that does this. I don't recommend what I answered there and instead recommend my answer below.

Accedi per commentare.

### Più risposte (1)

Image Analyst il 9 Ago 2015
What does "compare" mean to you? If you want to scan an image with a 3x3 window and just create an output image where the the pixel is true if it's the greatest/highest value in a 3x3 window, use imregionalmax():
% See where the pixel is greater then the 8 surrounding neighbors
regionalMaxImage = imregionalmax(grayImage, 8);
Attached below the image is the full demo:
##### 2 CommentiMostra NessunoNascondi Nessuno
kiruthika r il 9 Ago 2015
regionalMaxImage = imregionalmax(grayImage, 8); This instruction will give output even when the neighboring pixel has same value as central pixel. Only the central pixel should have the higher value than the 8 neighbor pixel.
Image Analyst il 9 Ago 2015
In that case, use imdilate() with a ring-shaped structuring element and a < comparison:
% Create a kernel to get the max of the 8 surrounding pixels
structuringElement = [1,1,1;1,0,1;1,1,1];
% Do the dilation
dilatedImage = imdilate(grayImage, structuringElement);
% See where the pixel is greater then the 8 surrounding neighbors
itsBigger = dilatedImage < grayImage;
% Display the local max image.
subplot(2, 1, 2);
imshow(itsBigger, []);
axis on;
title('Local Max', 'FontSize', fontSize, 'Interpreter', 'None');

Accedi per commentare.

### Categorie

Scopri di più su Image Segmentation and Analysis in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by