2

I want to compute the Color Layout Descriptor (CLD) for each image.. this algorithm include four stages . in the First stage I must Partition each image into 64 block i(8×8)n order to compute a single representative color from each block .. I try to partition the image into 64 block by using (For loop) but I get 64 ting image. I want to get image with (8×8) block in order to complete the algorithm by apply the DCT transformation then Zigzag scanning

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
zenab
  • 229
  • 3
  • 9
  • 20
  • 3
    The solution is fairly straightforward. If you can show me that you care for any help by starting to accept answers, I'll share my solution with you. – Jonas Mar 06 '11 at 01:57
  • please, can you explain what do you mean? I ask question and I need the solution if you have.. Is there is any problem with my question? – zenab Mar 06 '11 at 03:41
  • @zenab, you've asked 10 questions so far. people have taken the time and effort to answer your questions, yet you don't acknowledge their help by marking answers as accepted. this just gives you a reputation here as a freeloader, who uses stackoverflow as a homework solving resource. –  Mar 06 '11 at 03:42
  • this not truth .. Always I write commont for any suitable answer and I am not freeloader by using stackowerflow as homework solving resourceز – zenab Mar 06 '11 at 04:14
  • I think it is better to help each other as much as possible and no need to use a bad word against others – zenab Mar 06 '11 at 04:14
  • for every thing I thank you and no problem if you didn't like to help me – zenab Mar 06 '11 at 04:35
  • 2
    zenab, i'm just explaining what jonas meant. under each answer's vote number and up-down arrows, there is a check mark (tick mark). if you like an answer or if it helped you do what you wanted, just click on that. that's all jonas was asking you to do. I don't blame you... if you are new to stackoverflow, it's not always clear that you have to do it, and i didn't do it the first time either. anyway, i have answered your question below. –  Mar 06 '11 at 05:35

2 Answers2

5

One way to partition your image into blocks and then run some processing on it is to use the built-in function BLOCKPROC (called blkproc in older versions of Matlab).

%# find block length in order to get 64 blocks
imageSize = size(img);
blockLen = round(imageSize(1:2)/8);

%# apply a function to each block
out = blocproc(img,blockLen,@myFunction)

myFunction is the function that you'd like to apply to each block. You can define it as a subfunction of your code, or a separate m-file, or an anonymous function. The output will be catenated in an 8x-by-8x array, where x is the size of the output of your function. myFunction should expect a single input argument, blockStruct, which is a structure with fields data containing the pixel values of the block, as well as fields border, blockSize, imageSize, and location.

Jonas
  • 74,690
  • 10
  • 137
  • 177
  • thank you so much .. just I like to mention that blocproc it is write as blkproc.. I apply your code and I get what I want .. thank you again – zenab Mar 07 '11 at 02:22
  • Sorry I forget to ask you... when I used blkproc function I must convert the image to gray level by using rgb2gray function .. It is write or not? because when I didn't convert to gray level I get the following error:Subscripted assignment dimension mismatch. Error in ==> blkproc at 89 aa(border(1)+(1:ma),border(2)+(1:na)) = a; I want to compute the color layout descriptor (CLD).. If there is any effect on my result if I convert to gray level? – zenab Mar 07 '11 at 02:29
  • @zenab: Good point about `blkproc`: This function has seen a name change in recent years. While the current version (`blockproc`) can handle 3D input arrays, it appears that the old version (`blkproc`) cannot. Since `rgb2gray` will (roughly) give you the brightness of the image, you will most likely lose some information required for CLD. – Jonas Mar 07 '11 at 02:52
  • thank you for these information... I will try to use the new version because now I use R2008a.. – zenab Mar 07 '11 at 02:55
  • Hi Jonas, I would like to inform you that I am tried to use matlab version 2009... but also this version uses blkproc, could you please tell me which matlab version is using the blockproc function instead of blkproc? – zenab Mar 13 '11 at 01:57
  • 1
    @zenab: `blockproc` came out in 2009b. – Jonas Mar 13 '11 at 02:33
2

Here some pieces of code that I wrote for the exact same problem (8x8 blocks, DCT coefficients, etc) sometime ago...

img=imread('filename')
[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);

        <insert any other code you want to run here>
    end
end

slide_len sets the offset between one block and the next. In this case it offsets by one pixel each time. however, if you want non-overlapping blocks, you should set it to 8. usually in this application, you use some overlaps.

  • Now I tick mark before I apply your answer ..when I get the result I will inform you ... I would like to inform you I didn't need overlaying computing CLD. I need just this 64 blocks..thank again and I apologize to you for misunderstanding thank a lot. – zenab Mar 06 '11 at 06:08
  • I apply your coding, but I get 1875 block... Please I am trying to apply the CLD method as explain in Wikipedia website ... I mean I want to divide each image (with size 200×200) into 64 block in this case each block become with size (25×25) to get (8×8) block.. I hope I explain my problem clearly . – zenab Mar 06 '11 at 06:57
  • ah I see... you need to partition the image into 64 blocks. each block is 25x25, right? in that case, set `block_size=25` and `slide_len=25`. –  Mar 06 '11 at 15:50
  • o'b: You can achieve the same without using for-loops. See @Jonas' answer. – abcd May 12 '11 at 20:38