How to downsample an image by taking the average
이전 댓글 표시
I have a grayscale image A of size 512x512. I want to downsample this image by a factor of 3. This normally means that the first of the 3 pixels is selected as the output pixel value and the rest two pixels are discarded. However, I want to perform downsampling by a factor of 3 such that the average of the three pixels is taken and selected as the output value. I want to perform this along the row and the column of the image. Is there a built-in function within Matlab for this one? Any idea would be appreciated.
Thanks
답변 (1개)
Image Analyst
2015년 6월 27일
Use imresize() function - it's meant for this kind of thing.
smallImage = imresize(bigImage, 1/3, 'bilinear');
There are other interpolation options also, so look at the documentation.
댓글 수: 3
Robert Jansen
2021년 3월 24일
A bilinear downsample is definitely NOT the same as averaging over a window.
Image Analyst
2021년 3월 24일
편집: Image Analyst
2021년 3월 26일
If the difference really is important to @mona, she can use blockproc(). Since you forgot to post the code, I'll post that way of doing it below:
averagingFunction = @(x) mean(x.data(:))
smallImage = blockproc(bigImage, [3, 3] , averagingFunction)
Thanks Robert for pointing out that there are differences.
Attached are several very useful and informative demos on how to use blockproc() in a variety of ways.
Daniel Torres
2023년 4월 24일
What is the difference between bilinear and averaging? Is it something that could have an important impact on my analysis? I have checked the result of both processes and there is no big difference to my inexpert eyes.
Thanks
카테고리
도움말 센터 및 File Exchange에서 Blocked Images에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!