Exclude central pixel from sliding mean calculation of surrounding pixels in a matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Simone A.
il 18 Gen 2023
Commentato: Simone A.
il 18 Gen 2023
I have got a matrix (M) where I need to calculate the average of the surrounding (3x3) pixels for each pixel, excluding the central one.
I have tried colfilt, but this calculates the mean including the central pixel:
avg = (colfilt(M,[3 3],'sliding',@nanmean));
What I need to do is to exclude the central pixel of each 3x3 matrix from the mean calculation, and assign to that central pixel the value of the average of the surrounding 8 pixels. Schematically:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1267640/image.png)
Any help would be massively appreciated!
0 Commenti
Risposta accettata
Image Analyst
il 18 Gen 2023
Try setting the central pixel of the kernel to 0.
kernel = ones(3, 3) / 8;
kernel(2, 2) = 0;
avg = conv2(M, kernel, 'same');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!