Ejemplo n.º 1
0
def denoise_tv_bregman(inputImg, weight, max_iter, eps, isotropic, show):

    # documentation: https://scikit-image.org/docs/dev/api/skimage.restoration.html#skimage.restoration.denoise_tv_bregman

    tvImg = skimage.restoration.denoise_tv_bregman(inputImg, weight=weight, max_iter=max_iter, eps=eps, isotropic=isotropic)

    # standard params skimage.restoration.denoise_tv_bregman(image, weight, max_iter=100, eps=0.001, isotropic=True)
    print("shape is", len(tvImg.shape))

    tvImg = tvImg * 255
    tvImg = cv2.convertScaleAbs(tvImg)
    #tvImg = cv2.cvtColor(tvImg, cv2.COLOR_BGR2GRAY)

    #tvImg = img_as_ubyte(tvImg)
    print("shape is", len(tvImg.shape))
    if show:
        m3F.imshow(tvImg, "Total variation Bregman")

    return tvImg
Ejemplo n.º 2
0
def removeEyelid(eye, show):
    gray = cv2.cvtColor(eye.iris, cv2.COLOR_BGR2GRAY)
    
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)

    height, width = gray.shape

    grayPil = m3F.typeSwap(gray)

    for i in eye.circle[0, :]:
        for y in range(width-1):
            for x in range(height-1):
                pixel = grayPil.getpixel((y,x))

                if math.sqrt(((y-i[0])**2)+((x-i[1])**2)) < i[2] and pixel != maxVal:
                    gray[x, y] = 255
                else:
                    gray[x,y] = 0
        break

    m3F.imshow(gray, "iris")

    kernel1 = np.ones((15, 15), np.uint8)
    kernel2 = np.ones((7, 7), np.uint8)
    closing1 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel1,iterations=3)
    opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel2)

    m3F.imshow(closing1,"closed. Kernel 15, 3 iterations")
    m3F.imshow(opening,"opened. Kernel 7")

    return closing1
Ejemplo n.º 3
0
def semicircle(eye, show):
    #path = "output_eyes/photo19_Face_1_Left.jpeg"
    #iris = "iris_test2.jpeg"
    #img = cv2.imread(path)

    #img = eye.wip
    img = eye.iris
    cimg = img
    m3F.imshow(cimg, "cimg")

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    canny = cv2.Canny(img, 100, img.shape[0])

    m3F.imshow(canny, "semi circle canny")

    for i in eye.circle[0, :]:
        center = (i[0], i[1])
        radius = i[2]
        #cv2.circle(cimg, center, 3, (0,255,255), 0)
        #cv2.circle(cimg, center, radius, (0,0,255), 0)

    dt = cv2.distanceTransform(255 - canny, cv2.DIST_L2, 5)

    minInlierDist = 2.0

    for i in eye.circle[0, :]:
        counter = 0
        inlier = 0
        center = (i[0], i[1])
        radius = i[2]

        maxInlierDist = radius / 200.0
        if (maxInlierDist < minInlierDist):
            maxInlierDist = minInlierDist

        t = 0
        while t < 2 * cmath.pi:
            counter += 1
            cX = int(radius * cmath.cos(t) + i[0])
            cY = int(radius * cmath.sin(t) + i[1])
            try:
                if (dt[cY, cX] < maxInlierDist and gray[cY, cX] > 100):
                    inlier += 1
                    cv2.circle(cimg, (cX, cY), 3, (255, 0, 0))
            except IndexError:
                print("skipped")

            t += 0.1

    finalImg = cv2.cvtColor(cimg, cv2.COLOR_BGR2RGB)
    if (show):
        m3F.imshow(finalImg, "semicircles")
    #return finalImg
    return eye
def removeEyelid(eye, show):
    #m3F.imshow(eye.iris,"removeEyelid")
    print("type: eye, iris -", type(eye), type(eye.iris))
    print("length of iris -", len(eye.iris))
    gray = cv2.cvtColor(eye.iris, cv2.COLOR_BGR2GRAY)
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
    print("maxVal", maxVal)
    print("minVal", minVal)

    height, width = gray.shape

    grayPil = m3F.typeSwap(gray)

    for i in eye.circle[0, :]:
        for y in range(width - 1):
            for x in range(height - 1):
                pixel = grayPil.getpixel((y, x))
                #print("pixel",pixel)
                if math.sqrt(((y - i[0])**2) + ((x - i[1])**2)) < i[2]:
                    if pixel != maxVal or math.sqrt(((y - i[0])**2) + (
                        (x - i[1])**2)) < i[2] / 2:
                        gray[x, y] = 255

                    else:
                        #print("done here")
                        #gray.putpixel((x,y),minVal)
                        gray[x, y] = 0
        break

    #gray = m3F.typeSwap(gray)

    m3F.imshow(gray, "iris blob")

    kernel1 = np.ones((15, 15), np.uint8)
    kernel2 = np.ones((7, 7), np.uint8)
    closing1 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel1, iterations=3)
    #closing2 = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel2)
    opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel2)

    m3F.imshow(closing1, "closed. Kernel 15, 3 iterations")
    m3F.imshow(opening, "opened. Kernel 7")
    #m3F.imshow(closing2,"closed. Kernel 3")
    return closing1
Ejemplo n.º 5
0
def medianFilter(inputImg, show):
    outputImg = cv2.medianBlur(inputImg, 3)
    if (show):
        m3F.imshow(outputImg, "Median")
    return outputImg
Ejemplo n.º 6
0
def medianFilter(inputImg, kernelSize, show):
    outputImg = cv2.medianBlur(inputImg, kernelSize)
    if (show):
        m3F.imshow(outputImg, "median blur")
    return outputImg
Ejemplo n.º 7
0
def run(tempeye, tempResolution, tempMin_dist, tempParam_1, tempParam_2,
        tempMinRadius, tempMaxRadius, tempShow):
    print(
        "***************************************************************************************"
    )

    img = tempeye
    print(tempMinRadius)
    isEyeClass = False
    eye = None
    if isinstance(img, type(m3Class.Eye())):
        isEyeClass = True
        eye = tempeye
        img = eye.wip
    if not isinstance(img, type(None)):
        cimg = img

        if len(img.shape) == 3:
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        circles = cv2.HoughCircles(img,
                                   cv2.HOUGH_GRADIENT,
                                   tempResolution,
                                   tempMin_dist,
                                   param1=tempParam_1,
                                   param2=tempParam_2,
                                   minRadius=tempMinRadius,
                                   maxRadius=tempMaxRadius)

        #        circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,,120,param1=200,param2=10,
        #                                   minRadius=int(m3F.typeSwap(img).height/6),maxRadius=int(m3F.typeSwap(img).height/2.5))

        if not isinstance(circles, type(None)):

            if (circles.size != 0):
                circles = np.uint16(np.around(circles))
                # print(circles)
                index = 0
                for i in circles[0, :]:
                    #if img[i[1],i[0]] < 15:

                    # draw the outer circle
                    cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255 - index, 0),
                               2)
                    # draw the center of the circle
                    cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255 - index), 3)
                    index += 30

            if (tempShow):
                m3F.imshow(cimg, "Circle")
                m3F.printGreen("CIRCLES FOUND^^^")
                print("img out", img.shape)
            if isEyeClass:
                eye.circle = circles
                print("RETURNED AN EYE WITH CIRCLES")
                return eye
            else:
                return img
        else:
            if (tempShow):
                m3F.imshow(cimg, "no circles found")
                m3F.printRed("NO CIRCLES FOUND^^^")
    else:
        m3F.printRed("Image is NONE")
Ejemplo n.º 8
0
def runDouble(tempeye, tempResolution, tempMin_dist, tempParam_1, tempParam_2,
              tempMinRadius, tempMaxRadius, tempShow):
    print(
        "***************************************************************************************"
    )

    img = tempeye
    print(tempMinRadius)

    if not isinstance(img, type(None)):
        cimg = img
        if len(img.shape) == 3:
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        bwimg = img.copy()

        circles = cv2.HoughCircles(img,
                                   cv2.HOUGH_GRADIENT,
                                   tempResolution,
                                   tempMin_dist,
                                   param1=tempParam_1,
                                   param2=tempParam_2,
                                   minRadius=tempMinRadius,
                                   maxRadius=tempMaxRadius)

        if not isinstance(circles, type(None)):

            if (circles.size != 0):
                circles = np.uint16(np.around(circles))
                # print(circles)

                for i in circles[0, :]:
                    bwimg.fill(0)
                    # draw the outer circle
                    cv2.circle(bwimg, (i[0], i[1]), i[2], 255, -1)
                    # draw the center of the circle
                    # cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)
                    # m3F.imshow(bwimg,"circle")

                    mask = cv2.bitwise_and(img, bwimg)
                    # finalImg = cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)

                    #m3F.imshow(mask, "final img")

                    pupilCircle = cv2.HoughCircles(mask,
                                                   cv2.HOUGH_GRADIENT,
                                                   1,
                                                   50,
                                                   param1=200,
                                                   param2=10,
                                                   minRadius=int(i[2] / 6),
                                                   maxRadius=int(i[2] / 4 * 3))
                    if not isinstance(pupilCircle, type(None)):

                        if (pupilCircle.size != 0):
                            pupilCircle = np.uint16(np.around(pupilCircle))
                            # print(circles)
                            for j in pupilCircle[0, :]:
                                wiggle = 5
                                if i[0] + wiggle > j[0] > i[0] - wiggle and i[
                                        1] + wiggle > j[1] > i[1] - wiggle:
                                    # draw the outer circle
                                    cv2.circle(mask, (j[0], j[1]), j[2],
                                               (255, 255, 0), 1)
                                    # draw the center of the circle
                                    cv2.circle(mask, (j[0], j[1]), 2,
                                               (0, 0, 255), 3)
                            m3F.imshow(mask, "final img")

            if (tempShow):
                m3F.imshow(cimg, "Circle")
                m3F.printGreen("CIRCLES FOUND^^^")
                print("img out", img.shape)
            return img
        else:
            if (tempShow):
                m3F.imshow(cimg, "no circles found")
                m3F.printRed("NO CIRCLES FOUND^^^")
    else:
        m3F.printRed("Image is NONE")
Ejemplo n.º 9
0
def run(tempeye, tempResolution, tempMin_dist, tempParam_1, tempParam_2,
        tempMinRadius, tempMaxRadius, tempShow):
    print(
        "***************************************************************************************"
    )

    img = tempeye.copy()
    print(tempMinRadius)
    # isEyeClass = False
    # eye = None
    # if isinstance(img, type(m3Class.Eye())):
    #     isEyeClass = True
    #     eye = tempeye
    #     img = eye.wip.copy()
    # print("DID EYE")
    if not isinstance(img, type(None)):
        cimg = img.copy()

        if len(img.shape) == 3:
            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        # print("Hough run : min:", tempMinRadius, " max: ", tempMaxRadius)
        circles = cv2.HoughCircles(img,
                                   cv2.HOUGH_GRADIENT,
                                   tempResolution,
                                   tempMin_dist,
                                   param1=tempParam_1,
                                   param2=tempParam_2,
                                   minRadius=tempMinRadius,
                                   maxRadius=tempMaxRadius)

        #        circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,,120,param1=200,param2=10,
        #                                   minRadius=int(m3F.typeSwap(img).height/6),maxRadius=int(m3F.typeSwap(img).height/2.5))
        # print("circles!!!!", circles)
        # return circles
        if not isinstance(circles, type(None)):

            if (circles.size != 0):
                circles = np.uint16(np.around(circles))
                # print(circles)
                index = 0
                if (tempShow):
                    for i in circles[0, :]:
                        # if img[i[1],i[0]] < 15:
                        # draw the outer circle
                        cv2.circle(cimg, (i[0], i[1]), i[2], (0, 255, 0), 2)
                        # draw the center of the circle
                        cv2.circle(cimg, (i[0], i[1]), 2, (0, 0, 255), 3)
                # eye.houghOutline = cimg

                    m3F.imshow(cimg, "Circle")
                    m3F.printGreen("CIRCLES FOUND^^^")
                    print("img out", img.shape)
            return circles
        else:
            # eye.noCircles = True
            if (tempShow):
                m3F.imshow(cimg, "no circles found")
                m3F.printRed("NO CIRCLES FOUND^^^")
            return None
    else:
        m3F.printRed("Image is NONE")
Ejemplo n.º 10
0
def denoise(inputImg, show):
    outputImg = cv2.fastNlMeansDenoisingColored(inputImg, 7, 21, 10, 10)
    if (show):
        m3F.imshow(outputImg, "Denoised")
    return outputImg