how to average the specific pixel value over a window
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
how to average the specific pixel value over a window like 3x3 or 4x4 window
2 Commenti
DGM
il 30 Mag 2021
Modificato: DGM
il 30 Mag 2021
Your description isn't clear. The output of a single evaluation of a moving 2D filter is usually 1 pixel. The notion of keeping certain values in the sample set (the 3x3 sample) makes no sense in this context.
If the goal is to ignore white pixels such that they don't contribute to the average, that's a different thing. What should happen if all 9 sampled pixels are white?
Also, do you have Image Processing Toolbox?
Abhishek K P
il 30 Mag 2021
If the goal is to ignore white pixels such that they don't contribute to the average, that's a different thing. What should happen if all 9 sampled pixels are white?
What u told is right sir I need to ignore high intensity pixel 255 and have to average all other pixels in the 3x3 window If all the pixels are white that is high intensity pixels 255 then I have keep it as 255 - sir here is the condition 1. While sliding a 3x3 window on image 2.if there are white(255) pixels are more than other pixels then I have to keep 255 and replace center pixel value by 255 3.if there are below (255) pixels are more inside that 3x3 window... Then I have to take average of below(255)pixels then have to take average of only below(255) pixels and replace as the center pixel value I have to take 255(white pixels) as center during sliding a 3x3 window I need a code for it please do help with loop I need because I have to take all 255(white)pixels in a image and have to change the value of each and every white pixel
Sir I have found out the pixel values using coordinates (x, y) = find(I==255) I got the each and every coorodintes and pixels of 255(white) from this now I need to apply averaging as I explained above for every pixel Please do help me with the code
Risposte (1)
DGM
il 30 Mag 2021
Modificato: DGM
il 30 Mag 2021
If the majority of pixels are white, the result is white, but otherwise average the nonwhite pixels.
Such a filter can be made using nlfilter() from IPT; otherwise, you'd have to do it with loops. If you want edge treatment other than zero-padding, you'll have to do it with loops.
A = uint8(min(randi(500,100,100)-1,255));
B = uint8(nlfilter(A,[3 3],@procsample));
imshow(cat(1,A,B))
function px = procsample(samp)
mk = samp<255;
if sum(mk)<=4
px = mean(samp(mk));
else
px = 255;
end
end
If you need to do this with loops, just pad the array (use padarray() or do it manually). Loop through the image using the above calculations at each point to assign the values to the output image. There are examples of sliding window filters around. I don't feel like writing another.
0 Commenti
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!