Difference between blockproc() and for loop method of splitting an image with overlap?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
So I'm required to split an image into overlapping blocks of 8x8 and 4x4 pixels overlap, and perform dct on each block after that. I know of two methods blockproc() and a for loop method of splitting the image. But I'm wondering, would the output(dct matrix) be different between the methods?
For what i understood, the blockproc() method creates a border around the image in case of overlapping where as the for loop method from https://matlab.fandom.com/wiki/Split_image_into_blocks does not. (Note, the method in the link is for non-overlapping, but some modifications can be made for overlapping, which i did). In the case of blockproc(), the code is:
T2 = dctmtx(8);
dct_2 = @(block_struct) T * block_struct.data * T';
B1 = blockproc(I, [4 4], dct_2, 'BorderSize',[2 2], 'TrimBorder', false, 'PadPartialBlocks',true)
'BorderSize' [2 2] means that blockproc creates a border of 2 pixles top, down, right and left of the image and performs dct then. But in the case of the for loop method above, it doesn't use any borders for padding. Hence the dct when computed by each method will be different. I would like to know which method is more feasible and correct.
0 comentarios
Respuestas (1)
Guillaume
el 10 de Ag. de 2019
Editada: Guillaume
el 10 de Ag. de 2019
Hum, a for loop just iterates over whatever you want and execute whichever code you want. You can write a for loop that does exactly the same as blockproc, or something different. The choice is up to you. There's no inherent for loop method. It's whatever you want it to be.
However, note that blockproc doesn't do overlapping blocks. Also note that by default blockproc does not add a border, despite your statement.
One of the functions you can use for processing along a sliding-window is nlfilter. This function does indeed pad the image if necessary (if you don't want that just trim the image). If it's possible, you should be using colfilt instead.
But regardless which function you choose, again, you can implement the exact same thing with for loops and any deviation is your choice.
4 comentarios
Guillaume
el 12 de Ag. de 2019
would I even have to consider padding the image
That depends solely on your algorithm. Does it require blocks that are always the same size? If so, then you'll either have to pad the smaller blocks (when you reach the edges of the image) or ignore these blocks. If your algorithm doesn't care about the size of the blocks, then padding is not necessary.
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!