How to write code for 3x3 sliding window to process over a Image with Pixel size of 256x256
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Manoja YK
am 10 Jun. 2020
Kommentiert: Manoja YK
am 19 Jun. 2020
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
0 Kommentare
Akzeptierte Antwort
Rushi Vyas
am 19 Jun. 2020
Bearbeitet: Rushi Vyas
am 19 Jun. 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
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!