This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IMGLIB Help: Using IMG_dilate_bin

Hi,

I am using the IMG_dilate_bin filter from "imglib_c66x_3_1_0_1" for C6678 device with CCS v5.2. However, i cannot obtain the correct output.

I wrote a little test in C++ to communicate the issue:

#include <stdio.h>
extern "C" {
#include <IMG_dilate_bin.h>
}

int main (void)
{

unsigned int dilate_height = 8;
unsigned int dilate_width = 8;
unsigned char dilate_input[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                              0x00, 0x05, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00,
                                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                              0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
                                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                              0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

char dilate_mask[9] = { -1, 1, -1,
                                            1, 1, 1,
                                           -1, 1, -1 };

unsigned char dilate_output[64] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

// apply the TI dilate filter 
IMG_dilate_bin(dilate_input, dilate_output, dilate_mask, dilate_width);

// Printing the output
int i, j;
printf("\n\n{\n");
for (i = 0; i < dilate_height; ++i)
{
     for (j = 0; j < dilate_width; ++j)
     {
          printf("%d, \t", dilate_output[i*dilate_width + j]);
     }
     printf("\n");
}
printf("\n}\n\n");

return 0;

}

The code above generated the following output:

[C66xx_0] {
[C66xx_0] 192, 7, 124, 0, 0, 7, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0] 0, 0, 0, 0, 0, 0, 0, 0,
[C66xx_0]
[C66xx_0] }

Hence, only the first row is processed. 
Then I decided to look inside the IMG_dilate_bin.c file. I decided to replace the MUST_ITERATE and UNROLL pragmas with a for loop and also pass in the "rows" (in addition to the "cols"), and the filter seems to process on all the lines. However, the resulting output is not 100% correct excluding the borders.

Could you please help me as to how to use the filter properly?

  • Hi Rajasekaran,

    As per my initial post, the "dilate_input" is supposed to be a binary packed (8 pixels/byte).
    The binary filter should still work on the entire array instead of just the first row. As shown by the small test in my initial post, the IMG_dilate_bin function does not seem to iterate over the whole array.

    Could this be due to the #pragma MUST_ITERATE(2,,2) and #pragma UNROLL(2) compiler commands inside the "IMG_dilate_bin.c" file.

    Regards,
    Arvind Kishor

  • Arvind,

    Can you try replacing the last argument to the function 'dilate_width' with the total number of bytes in the output image, which is 64 in your case (dilate_width * dilate_height) and see if it works? The last argument to the function 'cols' represents the total number of bytes in the output, and not the number of columns.

    Thank you.

    Sincerely,

    Sudhakar Ayyasamy

  • Sudhakar,

    I tried your suggested solution. When I set dilate_width equal to 64 and then the output for that test is:

    [C66xx_0] {
    [C66xx_0] 255, 193, 255, 193, 193, 193, 255, 193,
    [C66xx_0] 255, 254, 239, 195, 1, 238, 248, 255,
    [C66xx_0] 255, 241, 255, 241, 241, 251, 255, 241,
    [C66xx_0] 255, 255, 255, 243, 129, 255, 255, 255,
    [C66xx_0] 255, 253, 255, 255, 255, 255, 255, 253,
    [C66xx_0] 255, 255, 255, 255, 249, 255, 255, 255,
    [C66xx_0] 255, 255, 255, 255, 255, 255, 255, 255,
    [C66xx_0] 255, 255, 255, 255, 255, 255, 255, 255,
    [C66xx_0]
    [C66xx_0] }

    I noticed that 'cols' does not represent the number of pixels, but instead the number of bytes. However, I thought the 'cols' represents number of bytes in one row and not the number of bytes in the whole image. I thought this because of the following lines of code inside the for loop of the "IMG_dilate_bin.c" file:

    p0l = _dtol(_memd8((void*)&in_data[i                ]));
    p3l = _dtol(_memd8((void*)&in_data[i + cols    ]));
    p6l = _dtol(_memd8((void*)&in_data[i + cols*2]));

    Note that this for loop runs from 0 to cols.

    Regards,
    Arvind

  • Sudhakar, 

    Something interesting worked. If I create the dilate_input 3 times the size of the actual input like so:

    unsigned char dilate_input[64*3] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x05, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

                                                                      0x00, 0x05, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x55, 0x55, 0x55, 0x55, 0x55, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                                                                      0x00, 0x05, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00 };

    And also use your suggestion of passing the total number of bytes of the image produced expected results:

    [C66xx_0] {
    [C66xx_0] 192,     7, 124,       0,      0,     7,     0,     0,
    [C66xx_0] 128,     2,   40,       0,      0,     2,     0,      0,
    [C66xx_0]      0, 128, 170, 170, 170, 170,   42,     0,
    [C66xx_0]      0, 192, 255, 255, 255, 255, 127,     0,
    [C66xx_0]      0, 128, 170, 170, 170, 170,   42,     0,
    [C66xx_0]      0,      0,     0,      0,      0,     0,      0,     0,
    [C66xx_0]      0,      0,     0,      0,      0,     0,      0,     0,
    [C66xx_0] 128,      2,   40,      0,      0,     2,      0, 128,
    [C66xx_0]
    [C66xx_0] }

    Regards,

    Arvind 

  • Arvind,

    Great! This should work for the entire image except the last two rows I guess. The last argument is in fact the number of bytes in one row as you mentioned. We are not passing the number of rows to this function, so the function has no idea of how many rows to operate on. So, it just operates on one row.

    So, like you just did, you can increase the size of image by adding two copies of input to it: first copy by shifting input upwards by one row and second copy by shifting input upwards by two rows (you can also fill the last row of first copy and last two rows of second copy with 0 instead of rotating the input). Then pass the new input, and original image's total number of bytes as 'cols'. The last two rows of output may not have valid output as they are operated on by first two rows of input in your case. For the rest of the image, this should give correct output.

    However, if your input is too large and if you don't have enough memory to create an extended input[width*height*3], you may have to use the IMG_dilate_bin() for each row of input:

    int i;
    for(i=0; i<dilate_height; i++)
     IMG_dilate_bin(dilate_input[i*dilate_width], dilate_output[i*dilate_width], dilate_mask, dilate_width);

    Thanks.

    Sincerely,

    Sudhakar Ayyasamy

  • Thanks Sudhakar, I will keep that in mind.

    However, I must mention the documentation is not clear. Hence, figuring out how to use this filter for a user is time-consuming / difficult. 

  • Arvind,

    I agree. It's not mentioned in the documentation that the function operates on one row. I will let the IMGLIB team know this. Thanks.

    Sudhakar

  • Hi Sudhakar,

    Additionally, We would recommend you to file IR(litbug) for document enhancement. Thank you for your support.