How to vectorize moving window across an image?
Afficher commentaires plus anciens
Hello,
I am trying to learn faster image processing techniques. I currently have implemented a double for loop that calculates a z-score and "throw away" the value if it is too close to the mean.
One option I considered was using a par for loop, but from my understanding, implementation using vectorization is a faster/better practice.
Here is the snippet of what I am trying to do:
inFrame = imread('Lenna.png');
% Convert frame into grayscale, use standard NTSC Conversion
grayFrame = 0.2989*inFrame(:,:,1) + 0.5870*inFrame(:,:,2) + 0.1140*inFrame(:,:,3);
[height, width, colormap] = size(grayFrame);
% Preallocate for window matrix
windowSize = 5;
window = zeros(windowSize);
zScoreMatrix = zeros(size(grayFrame));
% Begin moving window across image
for i = 3:height-2
for j = 3:width-2
window = grayFrame(i-2:i+2,j-2:j+2);
window = double(window);
mean = mean2(window);
std_dev = std2(window);
zScore = (window(3,3) - mean)/std_dev;
if abs(window(3,3) - mean) < 3
zScoreMatrix(i,j) = 0;
else
zScoreMatrix(i,j) = zScore;
end
end
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Explore and Edit Images with Image Viewer App dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
