資源簡介
python版本的形態學snake算法,里面包含測試圖片,可以運行測試

代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
morphsnakes
===========
This?is?a?Python?implementation?of?the?algorithms?introduced?in?the?paper
??Márquez-Neila?P.?Baumela?L.?álvarez?L.?“A?morphological?approach
??to?curvature-based?evolution?of?curves?and?surfaces“.?IEEE?Transactions
??on?Pattern?Analysis?and?Machine?Intelligence?(PAMI)?2013.
This?implementation?is?intended?to?be?as?brief?understandable?and?self-contained
as?possible.?It?does?not?include?any?enhancement?to?make?it?fast?or?efficient.
Any?practical?implementation?of?this?algorithm?should?work?only?over?the
neighbor?pixels?of?the?0.5-levelset?not?over?all?the?embedding?function
and?perhaps?should?feature?multi-threading?or?GPU?capabilities.
The?classes?MorphGAC?and?MorphACWE?provide?most?of?the?functionality?of?this
module.?They?implement?the?Morphological?Geodesic?Active?Contours?and?the
Morphological?Active?Contours?without?Edges?respectively.?See?the
aforementioned?paper?for?full?details.
See?test.py?for?examples?of?usage.
“““
__author__?=?“P.?Márquez?Neila?“
from?itertools?import?cycle
import?numpy?as?np
from?scipy?import?ndimage
from?scipy.ndimage?import?binary_dilation?binary_erosion?\
????????????????????????gaussian_filter?gaussian_gradient_magnitude
class?fcycle(object):
????
????def?__init__(self?iterable):
????????“““Call?functions?from?the?iterable?each?time?it?is?called.“““
????????self.funcs?=?cycle(iterable)
????
????def?__call__(self?*args?**kwargs):
????????f?=?next(self.funcs)
????????return?f(*args?**kwargs)
????
#?SI?and?IS?operators?for?2D?and?3D.
_P2?=?[np.eye(3)?np.array([[010]]*3)?np.flipud(np.eye(3))?np.rot90([[010]]*3)]
_P3?=?[np.zeros((333))?for?i?in?range(9)]
_P3[0][::1]?=?1
_P3[1][:1:]?=?1
_P3[2][1::]?=?1
_P3[3][:[012][012]]?=?1
_P3[4][:[012][210]]?=?1
_P3[5][[012]:[012]]?=?1
_P3[6][[012]:[210]]?=?1
_P3[7][[012][012]:]?=?1
_P3[8][[012][210]:]?=?1
_aux?=?np.zeros((0))
def?SI(u):
????“““SI?operator.“““
????global?_aux
????if?np.ndim(u)?==?2:
????????P?=?_P2
????elif?np.ndim(u)?==?3:
????????P?=?_P3
????else:
????????raise?ValueError(“u?has?an?invalid?number?of?dimensions?(should?be?2?or?3)“)
????
????if?u.shape?!=?_aux.shape[1:]:
????????_aux?=?np.zeros((len(P))?+?u.shape)
????
????for?_aux_i?P_i?in?zip(_aux?P):
????????_aux_i[:]?=?binary_erosion(u?P_i)
????
????return?_aux.max(0)
def?IS(u):
????“““IS?operator.“““
????global?_aux
????if?np.ndim(u)?==?2:
????????P?=?_P2
????elif?np.ndim(u)?==?3:
????????P?=?_P3
????else:
????????raise?ValueError(“u?has?an?invalid?number?of?dimensions?(should?be?2?or?3)“)
????
????if?u.shape?!=?_aux.shape[1:]:
????????_aux?=?np.zeros((len(P))?+?u.shape)
????
????for?_aux_i?P_i?in?zip(_aux?P):
????????_aux_i[:]?=?binary_dilation(u?P_i)
????
????return?_aux.min(0)
#?SIoIS?operator.
SIoIS?=?lambda?u:?SI(IS(u))
ISoSI?=?lambda?u:?IS(SI(u))
curvop?=?fcycle([SIoIS?ISoSI])
#?Stopping?factors?(function?g(I)?in?the?paper).
def?gborders(img?a
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-06-12?18:39??morphsnakes-master\
?????文件????????1485??2017-06-12?18:39??morphsnakes-master\LICENSE
?????文件????????4433??2017-06-12?18:39??morphsnakes-master\README.rst
?????目錄???????????0??2017-06-12?18:39??morphsnakes-master\examples\
?????文件?????1565913??2017-06-12?18:39??morphsnakes-master\examples\Figure10.png
?????文件?????1073903??2017-06-12?18:39??morphsnakes-master\examples\Figure12.png
?????文件??????994220??2017-06-12?18:39??morphsnakes-master\examples\Figure13.png
?????文件??????563534??2017-06-12?18:39??morphsnakes-master\examples\Figure14.png
?????文件?????1259086??2017-06-12?18:39??morphsnakes-master\examples\Figure9.png
?????文件?????2510561??2017-06-12?18:39??morphsnakes-master\examples\dendrite.gif
?????文件????????2927??2017-06-12?18:39??morphsnakes-master\examples\eq1.png
?????文件????????3511??2017-06-12?18:39??morphsnakes-master\examples\eq2.png
?????文件??????295294??2017-06-12?18:39??morphsnakes-master\examples\europe.gif
?????文件??????174887??2017-06-12?18:39??morphsnakes-master\examples\lakes.gif
?????文件??????144363??2017-06-12?18:39??morphsnakes-master\examples\nodule.gif
?????文件??????609464??2017-06-12?18:39??morphsnakes-master\examples\starfish.gif
?????文件???????11932??2017-06-12?18:39??morphsnakes-master\morphsnakes.py
?????目錄???????????0??2017-06-12?18:39??morphsnakes-master\testimages\
?????文件?????1152080??2017-06-12?18:39??morphsnakes-master\testimages\confocal.npy
?????文件???????23635??2017-06-12?18:39??morphsnakes-master\testimages\lakes3.jpg
?????文件??????196662??2017-06-12?18:39??morphsnakes-master\testimages\mama07ORI.bmp
?????文件??????157449??2017-06-12?18:39??morphsnakes-master\testimages\seastar2.png
?????文件????????2547??2017-06-12?18:39??morphsnakes-master\tests.py
評論
共有 條評論