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
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.
Chandvi Arora
Chandvi Arora 2017-7-21
I am just a beginner with very little knowledge in this area. I had a problem which I simply could not deal with, and hence I asked if anyone could help. This is the only reason I put up this question.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Timing and presenting 2D and 3D stimuli 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by