Using erode and dilate is similar to OpenCV morphologyEx (not supported by Rebol 3)
#!/usr/local/bin/r3
Rebol [
]
;--all images are binary with 1 channel
;--using erode and dilate is similar to OpenCV morphologyEx (not supported by Rebol 3)
cv: import opencv
with cv [
img: imread/with "../images/char.png" IMREAD_GRAYSCALE ;--source image as GS
threshold :img :img 127 255 THRESH_BINARY ;--binary thresholding
namedWindow win1: "Source"
moveWindow win1 0x0
imshow/name img "Source"
skel: Matrix [:img/size CV_8UC1] ;--1 channel matrix (8-bit)
element: getStructuringElement MORPH_CROSS 3x3 -1x-1 ;--structuring element for the kernel
until [
eroded: erode :img none element -1x-1 1 ;--erode
temp: dilate :eroded none element -1x-1 1 ;--then dilate
subtract :img :temp :temp ;--img source - eroded image
bitwise-or :skel :temp :skel ;--just OR operator
img: :eroded ;--update source image
maxi: second minMaxLoc img ;--get maxi value
maxi = 0 ;--repeat until maxi = 0
]
namedWindow win2: "Skeleton"
moveWindow win2 250x0
imshow/name skel win2
waitKey 0
destroyAllWindows
]
Rebol [
]
;--all images are binary with 1 channel
;--using erode and dilate is similar to OpenCV morphologyEx (not supported by Rebol 3)
cv: import opencv
with cv [
img: imread/with "../images/char.png" IMREAD_GRAYSCALE ;--source image as GS
threshold :img :img 127 255 THRESH_BINARY ;--binary thresholding
namedWindow win1: "Source"
moveWindow win1 0x0
imshow/name img "Source"
skel: Matrix [:img/size CV_8UC1] ;--1 channel matrix (8-bit)
element: getStructuringElement MORPH_CROSS 3x3 -1x-1 ;--structuring element for the kernel
until [
eroded: erode :img none element -1x-1 1 ;--erode
temp: dilate :eroded none element -1x-1 1 ;--then dilate
subtract :img :temp :temp ;--img source - eroded image
bitwise-or :skel :temp :skel ;--just OR operator
img: :eroded ;--update source image
maxi: second minMaxLoc img ;--get maxi value
maxi = 0 ;--repeat until maxi = 0
]
namedWindow win2: "Skeleton"
moveWindow win2 250x0
imshow/name skel win2
waitKey 0
destroyAllWindows
]

Aucun commentaire:
Enregistrer un commentaire