ios - Working to draw boundary around an object and the object is inside the image -
i trying draw boundary around object, in case lesion object inside image plain background not noise. had taken image , read pixel values.
and tried calculating xy coordinates along boundary of object using active contour algorithm boundary drew on edges of whole image instead on boundary along object inside, couldn't make better coordinates. can please suggest me if there better way find/draw boundary around object inside image or should go using opencv xcode better make ios app? kindly suggest.
i haven't tried using opencv's active contours, fact have near black , near white outline along image edges doesn't help
(input image provided in comments section above)
(this opencv+python prototype)
import cv2 import numpy np matplotlib import pyplot plt img = cv2.imread('skin.png') rgb_img = cv2.cvtcolor(img, cv2.color_bgr2rgb) red = rgb_img[:,:,0] height, width, channels = rgb_img.shape
create mask , apply flood-fill
mask = np.zeros((height+2, width+2), np.uint8) flooded = red.copy() flags = 4 | cv2.floodfill_mask_only cv2.floodfill(flooded, mask, (8, 8), 1, 2, 2, flags) plt.imshow(1-mask) plt.colorbar() plt.show()
kernel = cv2.getstructuringelement(cv2.morph_ellipse,(7,7)) omask = cv2.morphologyex(1-mask, cv2.morph_open, kernel) plt.imshow(omask) plt.colorbar() plt.show()
contours, hierarchy = cv2.findcontours(omask, cv2.retr_tree, cv2.chain_approx_simple )
find largest area contour:
largest_contour = [] largest_area = 0 contour in contours: area = cv2.contourarea(contour) if area > largest_area: largest_area = area largest_contour = contour
display result (a choice of rectangle , outline):
x,y,w,h = cv2.boundingrect(largest_contour) cv2.drawcontours(rgb_img, [largest_contour], -1, (0, 128, 128), 3) cv2.rectangle(rgb_img, (x,y), (x+w, y+h), (0, 0, 0), 2) plt.imshow(rgb_img) plt.show()
this straightforward , simple solution not perfect. can improved grabcut (at cost of computational complexity) or other techniques.
Comments
Post a Comment