How to divide an image into blocks if my image size is not a multiple of the given number?
1 view (last 30 days)
Show older comments
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 Comments
Stephen23
on 20 Jul 2017
Edited: Stephen23
on 20 Jul 2017
"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.
Answers (0)
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!