How to divide an image into blocks if my image size is not a multiple of the given number?

1 Ansicht (letzte 30 Tage)
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 Kommentare
Stephen23
Stephen23 am 20 Jul. 2017
Bearbeitet: Stephen23 am 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.
Chandvi Arora
Chandvi Arora am 21 Jul. 2017
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by