partioning the image
이전 댓글 표시
I want to divide the image into 6 blocks ,i used the code below,now i want to display those divided blocks,can tell how to display it please,I am performing CLD,PLEASE tell hoe to calculate the centroid from "out"
img=imread('dock.jpg')
[img_x,img_y]=size(img);
block_size=8;
slide_len=1;
for ix=block_size/2:slide_len:img_x-block_size/2
for jy=block_size/2:slide_len:img_y-block_size/2
current_block=img((ix-block_size/2+1):(ix+block_size/2),(jy-block_size/2+1):(jy+block_size/2));
dct_coeff=reshape(dct2(current_block),1,block_size^2);
out=zigzag(dct_coeff)
end
end
답변 (1개)
Walter Roberson
2012년 1월 19일
0 개 추천
Your code is overwriting your "out" matrix in each iteration, so at the end of the loop it does not have the necessary information to display all of the blocks.
You have not told us enough about zigzag() for us to predict what operations could be performed on "out".
댓글 수: 12
Pat
2012년 1월 19일
Walter Roberson
2012년 1월 19일
Please clarify how "frame" relates to your above description. Is a "frame" an individual image?
You did not tell us about zigzag()
It is not clear to me exactly what it is that the centroid is being taken of, but perhaps that would make more sense if I knew about zigzag().
Pat
2012년 1월 19일
Walter Roberson
2012년 1월 19일
zigzag() is your _implementation_ of an idea; we can see what you are passing in as input, but not what you do with it.
If you are doing CLD then why are you not dividing your image in to 64 blocks (instead of 6), and why are you not applying your algorithm to a color image (your size() call assumes 2D which can only happen with grayscale for .jpg images), and where are the other two DCT matrices and zigzag outputs that would be built for CLD stage 4 and 5? http://en.wikipedia.org/wiki/Color_layout_descriptor
Pat
2012년 1월 19일
Walter Roberson
2012년 1월 19일
In your Question, above, you wrote, "I want to divide the image into 6 blocks". Did you miss out the "4" of "64" ?
JPEG files can only store grayscale images (2D) or true-color images (3D) and JPEG cannot store indexed images (2D). If you are reading a color image, 3D, then [img_x,img_y]=size(img); is going to get the right number of rows stored in img_x, but the value stored in img_y is going to be the number of columns multiplied by the number of bands (3) . See the last syntax case in the size() documentation.
The DCT stage for CLD produces 3 DCT coefficient matrices; you appear to only be producing one.
Pat
2012년 1월 22일
Walter Roberson
2012년 1월 22일
Looks to me as if you would have one DCT coefficient matrix per color plane. But first you are going to have to find an image that is simultaneously 3D (truecolor) and not 3D (in order to work with your calls to size())
Pat
2012년 1월 23일
Walter Roberson
2012년 1월 23일
Can't be. Your line
[img_x,img_y]=size(img);
is only appropriate for 2D images.
Pat
2012년 1월 24일
Walter Roberson
2012년 1월 24일
And if it is not appropriate for your code to think that img_y is 1450 (or, more likely, 768) then you will need to change that line of code.
카테고리
도움말 센터 및 File Exchange에서 Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!