using discrete cosine transform to break 16x16 to 8x8 blocks
이전 댓글 표시
I have to break a image-pixel array down to 8x8 blocks. Here is my code
function imcompress(fig,fmt,mask)
p = imread(fig,fmt);
p = im2double(p);
siz = size(p)-rem(size(p),8);
for c = 1:3
i = j(1:siz(1),1:siz(2),c)
end
Q = dctmtx(8)
fund = @(R) Q*R*Q'
B = blockproc(i, [8 8],fund);
B = blockproc(B, [8 8],@(block) mask.*block.data);
fundid = @(R) Q'*R*Q
I2 = blockproc(B, [8 8],fundid)
I2 = p2(1:siz(1),1:siz(2),c)
imshow(i), figure, imshow(I2)
And I also got my mask function
function mask = mymask(n)
mask=zeros(8);
matr= fliplr(triu(ones(n)));
mask(1:n,1:n)=matr;
end
When I test the picture,which called picture.jpg, I typed imcompress('picture','jpg',mymask(8)) it said Error in imcompress (line 6) ,i = j(1:size(1),1:size(2),c) I am not sure what's wrong with my code. Can someone help me up, and point out some others error codes?
댓글 수: 3
Geoff Hayes
2014년 12월 10일
Jarvan - what is j in your line of code
i = j(1:siz(1),1:siz(2),c)
In fact, what are you trying to do with i as it gets updated at each iteration of the for loop and so overwrites the values from previous iterations?
As an aside, you should avoid naming variables i and j as these also correspond to the representation of the imaginary number.
jarvan
2014년 12월 13일
jarvan
2014년 12월 13일
채택된 답변
추가 답변 (1개)
Image Analyst
2014년 12월 15일
0 개 추천
The FAQ may interest you: http://matlab.wikia.com/wiki/FAQ#How_do_I_split_an_image_into_non-overlapping_blocks.3F
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!