How to write code for 3x3 sliding window to process over a Image with Pixel size of 256x256

8 vues (au cours des 30 derniers jours)
1. Choose the first pixel. Having it as the center pixel i have to form a 3x3 window. [Being the first pixel i've padded the Matrix with Zeros]
2. If that center Pixel is Noise Pixel it's location should be returned with all its neighborhood pixels. I will convert this 3x3 Matrix into a 1-D array and do my calculations to correct the corrupted pixels.
Here i'm struggling in designing the sliding 3x3 window to move over the image

Réponse acceptée

Rushi Vyas
Rushi Vyas le 19 Juin 2020
Modifié(e) : Rushi Vyas le 19 Juin 2020
Hi Manoja,
I understand you want to perform a 3x3 sliding window operation on a padded image. When you encounter noise, you want to flatten the 3x3 matrix and perform corrections.
The below code performs this operation:
%A is your image
B = padarray(A,[1 1]);
for i = 2:m-1
for j = 2:n-1
if mod(B(i,j), 10) == 0 %corrupt pixel condition
mat = B(i-1:i+1,j-1:j+1); % selecting your 3x3 window
arr = reshape(mat, [1 numel(mat)]); %convert to 1-D array
B(i,j) = sum(arr);%replaced with corrections
end
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits


Version

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by