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?

답변 (1개)

Walter Roberson
Walter Roberson 2019년 5월 6일

0 개 추천

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.

댓글 수: 1

lauren p
lauren p 2019년 5월 7일
Instead of using an 8x8 mask, i've chosen to use a 10x10 mask with my image that is 630X630. I have the following code, but when the compressed image shows, it is just black. Is there an error in my code?
clc; clear;
I = imread('kneemri.jpg');
I = im2double(I);
T = dctmtx(10);
dct = @(block_struct) T .* block_struct.data .* T';
B = blockproc(I,[10 10],dct);
mask = [1 1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0];
B2 = blockproc(B,[10 10],@(block_struct) mask .* block_struct.data);
invdct = @(block_struct) T' .* block_struct.data .* T;
I2 = blockproc(B2,[10 10],invdct);
imshow(I)
figure
imshow(I2)

댓글을 달려면 로그인하십시오.

질문:

2019년 5월 5일

댓글:

2019년 5월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by