What is a vectorized way to calculate variance of an image patch
이전 댓글 표시
I have a 560*560*3 image file, I want to divide the image into many small 8*8 patches, then calculate variance of each patch. What is a vectorized way to calculate variance of each image patch ?
댓글 수: 2
Walter Roberson
2015년 5월 30일
How do you want to calculate variance of color? If you have an 8 x 8 x 3 subsection, S, representing color, do you want var(S(:)), which treats all the pixel components equally? Or do you want variance of the grayscale equivalent, and thus variance of brightness? Or do you want to convert to HSL and do variance of Hue? Or.... ?
Victor Yi
2015년 5월 31일
채택된 답변
추가 답변 (2개)
Image Analyst
2015년 5월 31일
1 개 추천
You can use blockproc() (in the Image Processing Toolbox) to calculate the variance of each small tile of an image in a line or two of code since the function is meant for this purpose. Run my attached demos for an example.
Matt J
2015년 5월 31일
1 개 추천
Another approach to consider is stdfilt(), which will compute standard deviation in a sliding window fashion rather than a tiled fashion. This is more computation than you need. However, if stdfilt is sufficiently code-optimized, it might be worth it.
댓글 수: 3
Victor Yi
2015년 6월 1일
Image Analyst
2015년 6월 1일
And, if you want to do your own custom function with whatever crazy thing you can imagine, then you can use nlfilter(). It's like conv2(), imfilter(), stdfilt(), entropyfilt(), etc. except that you get to define your own custom code to apply at each filter window location.
GAURA YADAV
2020년 6월 19일
Thanks.
카테고리
도움말 센터 및 File Exchange에서 Polygons에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!