Error when using blockproc
Show older comments
I'm trying to perform image compression using blockproc and I'm inputting an image that is 630x630, however I am using a mask that is only 8x8. I get an error that says array dimensions must match for binary array op, which I'm guessing is being caused by the size of my mask. Is there an easy way to reduce the size of the image or increase the size of the mask so the image compression works?
Answers (1)
Walter Roberson
on 6 May 2019
0 votes
630 is not evenly divisible by 8: it is 78 groups of 8 pixels plus 6 left-order pixels. By default blockproc will process those left-over 8 x 6 blocks (along the right side) and those 6 x 8 blocks (along the bottom) and even the 6 x 6 lower right hand corner. And that is a problem for you because your code assumes every block is exactly 8 x 8 .
blockproc() gives you an option to pad blocks, which I have linked to above, and a related option to control what padding value is used for the blocks. That would turn those 8 x 6 or 6 x 8 or 6 x 6 blocks into 8 x 8 blocks by padding them. Sometimes that is quite acceptable, but other times it is a Problem with a capital-P .
In your case it might be acceptable to pad with 0, as long as the decompression side knows to remove the extra 2 rows or columns.
Categories
Find more on Image Transforms 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!