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.

Erosion function in IMGLib

I want use IMG_erode_bin function in imglib, but I don't understand what this function do.  When I refer to the description of this function in sprc264 , it shows:

---------------------------------------------------------------------------------------------------------------


Algorithm
              result = 1;
              if (mask[0][0] != DONT_CARE)   result  &=  input[y  +  0][x + 0];
              if (mask[0][1] != DONT_CARE)   result  &=  input[y  +  1][x + 1];
              if (mask[0][2] != DONT_CARE)   result  &=  input[y  +  2][x + 2];
              if (mask[1][0] != DONT_CARE)   result  &=  input[y  +  0][x + 0];
              if (mask[1][1] != DONT_CARE)   result  &=  input[y  +  1][x + 1];
              if (mask[1][2] != DONT_CARE)   result  &=  input[y  +  2][x + 2];
              if (mask[2][0] != DONT_CARE)   result  &=  input[y  +  0][x + 0];
              if (mask[2][1] != DONT_CARE)   result  &=  input[y  +  1][x + 1];
              if (mask[2][2] != DONT_CARE)   result  &=  input[y  +  2][x + 2];
              output [ y ] [x]  = result;
          For this code, DONT_CARE is specified by a negative value in the input mask.
          Non-negative values in the mask cause the corresponding pixel to be included in the
          erosion operation.
---------------------------------------------------------------------------------------------------------------

 I don't understand why this alg always AND among in diagonal direction of input image array.   For example:

Input  (  unsigned char input[24]    ) image array:

0 1 1 1 0 0 0 1

0 1 1 0 1 1 1 1

0 1 0 1 0 0 0 1

 

Mask (In my opinion, everything will not be effected if every value of this Mask is positive.)

0 0 0

1 1 1

0 0 0

 

IMG_erode_bin(input,output,(*mask)[3],8);    // unsigned char output[24]

The result is:

All of values in "output" is zero,  As the alg description above, I believe that at least one value of output array should be "1".

Please look at the bold and italic number in "input" array(here x = 1, y = 0). From alg description, "result" variant is 1,

result  &=  input[y  +  0][x + 0];      // 1 & = 1;

result  &=  input[y  +  1][x + 1];     //  1 & = 1;

result  &=  input[y  +  2][x + 2];     //  1 & = 1;

 

Where is wrong? I can not get  "1"  in output array.

 

By the way:

As I know, the erosion theory in image processing is not like the alg description.

 

Thanks.

  • Please help me

    Thank you.

  • As you said earlier, the DONT CARE element is a negative number.  Thus, your mask of 0's & 1's is really all the same value, a "do care".  You will only get a '1' in the output array if you have a set of 3x3 '1' pixels in your input... which you don't.  Maybe you want to replace the 0's in your mask with -1's?

  • Yes, If every value in mask is not negative, it will not affect how to get the result array. But I'm curious that why it always use "result" value to AND the diagonal direction as the alg description said.  And Why it is not horizontal direction or the virtical.

    Here I want to quote an array example to explain clearly, this example is from Wiki.
    ----------------------------------------------------------------------------------------------------------
    Example

    Suppose A is a 13 * 13 matrix and B is a 5 * 1 matrix:

        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 1 1 1 1 1 1 1 0 0 0            1
        0 0 0 1 1 1 1 1 1 1 0 0 0            1
        0 0 0 1 1 1 1 1 1 1 0 0 0            1
        0 0 0 1 1 1 1 1 1 1 0 0 0            1
        0 0 0 1 1 1 1 1 1 1 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

    Assuming that the origin B is at its center, for each pixel in A superimpose the origin of B, if B is completely contained by A the pixel is retained, else deleted.

    The Erosion of A by B is given by

        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 0 0 0 0 0 0
        0 0 0 0 0 0 0 0 0 0 0 0 0           
        0 0 0 1 1 1 1 1 1 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 0 0 0 0 0 0 0 0 0
        0 0 0 0 0 0 0 0 0 0 0 0 0
    ---------------------------------------------------------------------------------------------------------------
    In this example, A is input array, B is mask. As I know, the theory of erosion in image processing should be like this, so I don't know why the description of erosion in imgLib tells me to AND in diagnoal direction.

  • The mask allows for any style erosion you want to do.  To accomplish the vertical erosion in your example, set the diagonal & horizontal bits to DONT CARE (-1):

    -1  0  -1

    -1  0  -1

    -1  0  -1

    Notice that the algorithm only ANDS in directions if the mask bit != DONT CARE.

     

    Matt

  • I find a sample about Erosion in "<ccs path>\c6400\imglib\examples\img_erode_bin"(although I use c64+,I think I can refer to the idea of this sample), that tells me how the erosion function works. If anyone who's interested in this function, please refer to this sample.

    Thanks for Rudy Huang from TI asia.