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

4 ビュー (過去 30 日間)
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

採用された回答

Rushi Vyas
Rushi Vyas 2020 年 6 月 19 日
編集済み: Rushi Vyas 2020 年 6 月 19 日
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

その他の回答 (0 件)

タグ

製品


リリース

R2014b

Community Treasure Hunt

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

Start Hunting!

Translated by