Frei-Chen Edge Detector

Chintak Sheth chintaksheth at gmail.com
Wed Apr 24 05:48:00 EDT 2013


Hi Umesh,

Yes. You could create a new branch, commit and push it, and provide a link
to it maybe ?

Chintak


On Wed, Apr 24, 2013 at 3:13 PM, Umesh Sharma <usharma01 at gmail.com> wrote:

>
> Hi Stefan,
> Here is my code which i have written in edges.py
>
> ##############
>
> def freiChen(image,mask=None):
>     """Find the edge magnitude using FreiChen Filter.
>
>     Parameters
> ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen edge .
>     """
>     return np.sqrt(freiChen_edge1(image, mask)**2 +\
>                    freiChen_edge2(image, mask)**2 +\
>           freiChen_edge3(image, mask)**2 +\
>                    freiChen_edge4(image, mask)**2 +\
>                    freiChen_line1(image, mask)**2 +\
>                    freiChen_line2(image, mask)**2 +\
>                    freiChen_line3(image, mask)**2 +\
>                    freiChen_line4(image, mask)**2 )
>                    #freiChen_average(image, mask)**2)
>
>
> def freiChen_edge1(image, mask):
>     """Find the horizontal edges of an image using the FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen horizontal edge.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       1  sqrt(2)  1
>       0       0   0
>  -1 -sqrt(2) -1
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[ 1, sqrt(2), 1],
>                                        [ 0,       0, 0],
>                                        [-1,-sqrt(2),-1]]).\
> astype(float) / sqrt(8)))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_edge2(image, mask):
>     """Find the vertical edges of an image using the FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChan edges .
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>          1   0       -1
>     sqrt(2)  0  -sqrt(2)
>  1 0 -1
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[      1, 0,      -1 ],
>                                        [sqrt(2), 0, -sqrt(2)],
>                                        [      1, 0,      -1]]).\
> astype(float) / sqrt(8)))
>     return _mask_filter_result(result, mask)
>
> def freiChen_edge3(image, mask):
>     """Find the edges in an image having slope 135 degree FreiChen
> operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen edges.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>           0   -1   sqrt(2)
>           1    0       -1
> -sqrt(2)   1        0
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[       0,-1, sqrt(2)],
>                                        [       1, 0,      -1],
>                                        [-sqrt(2), 1,       0]]).\
> astype(float) / sqrt(8)))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_edge4(image, mask):
>     """Find the edges of an image having slope 45 degree using the
> FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The Freichen edges.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       sqrt(2)   -1         0
>           -1     0         1
>    0     1   -sqrt(2)
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[sqrt(2), -1,        0],
>                                        [     -1,  0,        1],
>                                        [      0,  1, -sqrt(2)]]).\
> astype(float) / sqrt(8)))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_line1(image, mask):
>     """Find the edge intersection in an image using the FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen lines.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       0   1   0
>      -1   0  -1
>       0   1   0
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[ 0, 1,  0],
>                                        [-1, 0, -1],
>                                        [ 0, 1,  0]]).astype(float) / 2.0))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_line2(image, mask):
>     """Find the intersection of edges in an image using the FreiChen
> operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen lines.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       -1   0   1
>        0   0   0
>        1   0  -1
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[-1, 0,  1 ],
>                                        [ 0, 0,  0],
>                                        [ 1, 0, -1]]).astype(float) / 2.0))
>     return _mask_filter_result(result, mask)
>
> def freiChen_line3(image, mask):
>     """Find the lines of an image using the FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen lines.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       1   -2   1
>      -2    4  -2
>       1   -2   1
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[ 1, -2,  1 ],
>                                        [-2,  4, -2 ],
>                                        [ 1, -2,  1]]).astype(float) / 6.0))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_line4(image, mask):
>     """Find the lines of an image using the FreiChen operator.
>
>     The kernel is applied to the input image, to produce separate
> measurements
>     of the gradient component one orientation.
>
>     Parameters
>     ----------
>     image : 2-D array
>         Image to process.
>     mask : 2-D array, optional
>         An optional mask to limit the application to a certain area.
>         Note that pixels surrounding masked regions are also masked to
>         prevent masked regions from affecting the result.
>
>     Returns
>     -------
>     output : ndarray
>         The FreiChen lines.
>
>     Notes
>     -----
>     We use the following kernel and return the absolute value of the
>     result at each point::
>
>       -2   1   -2
>        1   4    1
>       -2   1   -2
>
>     """
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[ -2, 1, -2 ],
>                                        [  1, 4,  1 ],
>                                        [ -2, 1, -2 ]]).astype(float) /
> 6.0))
>     return _mask_filter_result(result, mask)
>
>
> def freiChen_average(image, mask):
>     image = img_as_float(image)
>     result = np.abs(convolve(image,
>                              np.array([[ 1, 1, 1 ],
>                                        [ 1, 1, 1 ],
>                                        [ 1, 1, 1 ]]).astype(float) / 3.0))
>     return _mask_filter_result(result, mask)
> ##############
>
>
>
> Should i commit and upload to Git because it is easy to read ???
>
>
>
> Regards ,
>
> Umesh
>
> --
> You received this message because you are subscribed to the Google Groups
> "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scikit-image+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20130424/ea7d89f6/attachment.html>


More information about the scikit-image mailing list