How to divide an image into blocks if my image size is not a multiple of the given number?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Stephen23
el 20 de Jul. de 2017
Editada: Stephen23
el 20 de Jul. de 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Timing and presenting 2D and 3D stimuli en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!