How to divide an image into blocks if my image size is not a multiple of the given number?
2 次查看(过去 30 天)
显示 更早的评论
I have the following code with me to divide my bmp gray image into blocks:-
img = imread('C:\somewhere\someimage.bmp'); numblockheight = size(img, 1) / 8; numblockwidth = size(img, 2) / 8; assert(all(mod([numblockwidth, numblockheight], 1) == 0), 'Image size is not a multiple of 8') imageblocks = mat2cell(img, ones(1, numblockheight) * 8, ones(1, numblockwidth) * 8, size(img, 3))
The output is showing an error that my image is not a multiple of 8 as written in the code. But what to do in this case? How can I divide my image into blocks and display them as shown in the figure attached?
2 个评论
Stephen23
2017-7-20
编辑:Stephen23
2017-7-20
"But what to do in this case?"
How do we know this? This is your decision: you could ignore the remaining pixels, pad the image with pixels (virtual or real), overlap your samples, interpolate, sample smaller sub-matrices at the edges, etc, etc. What you do depends on your algorithm, which we know nothing about.
Don't panic and ask random strangers how your algorithm should work: stop and think about it yourself: how does your algorithm need to deal with the remaining pixels? Then research how to implement that.
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!