Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not an expert but from the first look it seems like a nice trick for high computational efficiency:

  • Precompute a costly operation tan(pi/8)
  • Use some bit shifting ( << operation) to do comparisons using int insteand of floats

it seems to be deciding which type of comparison with the if (dyVal < tg22x) lines and then goes and check the next pixels in the derivatives images (dx and dy).

 if (dyVal < tg22x) // this is for horizontal edges
    {
        if (m > tex2D(tex_mag, x - 1, y) && m >= tex2D(tex_mag, x + 1, y)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 1;
        }
    }
    else if(dyVal > tg67x) // this for vertical ones
    {
        if (m > tex2D(tex_mag, x, y - 1) && m >= tex2D(tex_mag, x, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 2;
        }
    }
    else // diagonals (uses s to switch direction of the diagonal)
    {
        if (m > tex2D(tex_mag, x - s, y - 1) && m >= tex2D(tex_mag, x + s, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = s > 0 ? 3 : 4;
        }
    }
    // mask(x,y) = flag;

Bottom line, that's where you need to set your flags.

For clarification, you wont be able to tell the "direction" in the sense of right to left vs left to right, just vertical, horizontal and two diagonal directions.

Hope this helps!

Not an expert but from the first look it seems like a nice trick for high computational efficiency:

  • Precompute a costly operation tan(pi/8)
  • Use some bit shifting ( << operation) to do comparisons using int insteand of floats

it seems to be deciding which type of comparison it needs to do with the if (dyVal < tg22x) lines and then goes and check the next pixels in the derivatives images (dx and dy).

 if (dyVal < tg22x) // this is for horizontal edges
    {
        if (m > tex2D(tex_mag, x - 1, y) && m >= tex2D(tex_mag, x + 1, y)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 1;
        }
    }
    else if(dyVal > tg67x) // this for vertical ones
    {
        if (m > tex2D(tex_mag, x, y - 1) && m >= tex2D(tex_mag, x, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 2;
        }
    }
    else // diagonals (uses s to switch direction of the diagonal)
    {
        if (m > tex2D(tex_mag, x - s, y - 1) && m >= tex2D(tex_mag, x + s, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = s > 0 ? 3 : 4;
        }
    }
    // mask(x,y) = flag;

Bottom line, that's where you need to set your flags.

For clarification, you wont be able to tell the "direction" in the sense of right to left vs left to right, just vertical, horizontal and two diagonal directions.

Hope this helps!

Not an expert but from the first look of it it seems like a nice trick for high computational efficiency:

  • Precompute a costly operation tan(pi/8)
  • Use some bit shifting ( << operation) to do comparisons using int insteand of floats

it seems to be deciding which type of comparison it needs to do with the if (dyVal < tg22x) lines and then goes and check the next pixels in the derivatives images (dx and dy).

 if (dyVal < tg22x) // this is for horizontal edges
    {
        if (m > tex2D(tex_mag, x - 1, y) && m >= tex2D(tex_mag, x + 1, y)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 1;
        }
    }
    else if(dyVal > tg67x) // this for vertical ones
    {
        if (m > tex2D(tex_mag, x, y - 1) && m >= tex2D(tex_mag, x, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = 2;
        }
    }
    else // diagonals (uses s to switch direction of the diagonal)
    {
        if (m > tex2D(tex_mag, x - s, y - 1) && m >= tex2D(tex_mag, x + s, y + 1)) {
            edge_type = 1 + (int)(m > high_thresh);
            // flag = s > 0 ? 3 : 4;
        }
    }
    // mask(x,y) = flag;

Bottom line, that's where you need to set your flags.

For clarification, you wont be able to tell the "direction" in the sense of right to left vs left to right, just vertical, horizontal and two diagonal directions.

Hope this helps!