How to write code for 3x3 sliding window to process over a Image with Pixel size of 256x256
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Rushi Vyas
on 19 Jun 2020
Edited: Rushi Vyas
on 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
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!