예제 #1
0
def myHMin(image, intensiteRelative, struct):
    gamma8 = strel.build("square", 1, None)

    for i in range(0, image.shape[0]):
        for j in range(0, image.shape[1]):
            if (image[i][j] + intensiteRelative <= 255):
                image[i][j] = image[i][j] + intensiteRelative
            else:
                image[i][j] = 255

    return myReconClose(image, struct, gamma8)
예제 #2
0
def myHMax(image, intensiteRelative, struct):
    gamma8 = strel.build("square", 1, None)

    for i in range(0, image.shape[0]):
        for j in range(0, image.shape[1]):
            if (image[i][j] - intensiteRelative >= 0):
                image[i][j] = image[i][j] - intensiteRelative
            else:
                image[i][j] = 0

    return myReconOpen(image, struct, gamma8)
예제 #3
0
def filterElementsOnEdge(image):
    gamma8 = strel.build("square", 1, None)

    imagePix = np.zeros(image.shape, image.dtype)
    for i in range(0, image.shape[0]):
        for j in range(0, image.shape[1]):
            if image[i, j] == 255 and (i == 0 or i == image.shape[0] - 1
                                       or j == 0 or j == image.shape[1] - 1):
                imagePix[i, j] = 255
                recInf = myReconInf(imagePix, image, gamma8)
                image = image - recInf

    return image
예제 #4
0
def countElements(image):
    gamma8 = strel.build("square", 1, None)

    imagePix = np.zeros(image.shape, image.dtype)
    count = 0
    for i in range(0, image.shape[0]):
        for j in range(0, image.shape[1]):
            if image[i, j] == 255:
                imagePix[i, j] = 255
                recInf = myReconInf(imagePix, image, gamma8)
                count += 1
                image = image - recInf

    return count
import cv2
import numpy as np
from src.main.python.myLibs.ImageProcessing.MorphologicalImageProcessing import structElement as strel, morpho, myimage

imagename = '../../../../resources/images/feuille1.png'
image = cv2.imread(imagename)
disc = strel.build("disc", 5, None)
gamma8 = strel.build("square", 5, None)
gamma4 = strel.build("diamond", 1, None)
gamma8list = strel.build_as_list("square", 1, None)

morpho.displayImage("Original Image", image)

# Unify background
image = 255 - image[:, :, 0]

image = image - morpho.myOpen(image, gamma8)
image = morpho.myThreshold(image, 60)

morpho.displayImage("Image threshold", image)

# Seeking orientation
sums = []
imageGrad = np.zeros(image.shape, image.dtype)
for angle in range(0, 90):
    line = strel.build("line", 100, angle)
    imageGrad = morpho.myOpen(image, line)
    sums.append((sum(map(sum, image - imageGrad)), angle))

orient = min(sums[:])[1] - 90
print("orientation : " + str(orient))
import cv2
from src.main.python.myLibs.ImageProcessing.MorphologicalImageProcessing import structElement as strel, morpho

#imagePath = '../../../../resources/images/papier_60.png'
#imagePath = '../../../../resources/images/papier_15.png'
imagePath = '../../../../resources/images/papier_35.png'

image = cv2.imread(imagePath)

morpho.displayImage("Image", image)

# Keep only the red color (better for these images)
image = image[:, :, 2]

# Test for various different angles
sums = []
for angle in range(-90, 90, 1):
    structLigne = strel.build("line", 40, angle)
    gradImage = morpho.myGrad(image, structLigne)
    sums.append((sum(map(sum, gradImage)), angle))

orient = min(sums[:])[1]

print("Orientation of the object : " + str(orient) + " degree")

key = cv2.waitKey(0)
cv2.destroyAllWindows()
예제 #7
0
import cv2
from src.main.python.myLibs.ImageProcessing.MorphologicalImageProcessing import structElement as strel, morpho

imagePath = '../../../../resources/images/numbers.png'
image = cv2.imread(imagePath)
morpho.displayImage("Original", image)

struct = strel.build("disc", 5, None)
open = morpho.myOpen(image, struct)
morpho.displayImage("Open", open)

image = image - open

image = morpho.myThreshold(image, 50)

morpho.displayImage("Final Image", image)

key = cv2.waitKey(0)
cv2.destroyAllWindows()
while 1:
    print('Select object')
    pointMarks = myimage.display_and_click_image(image, colorMarks)
    if len(pointMarks) > 0:
        marks = np.zeros([image.shape[0], image.shape[1]], np.dtype)
        for mark in pointMarks:
            marks[mark[0], mark[1]] = 255
        marksList.append(marks)
    else:
        print('End of Selection')
        break

image = image[:, :, 0]

gamma8 = strel.build("square", 1, None)
gamma8list = strel.build_as_list("square", 1, None)

gradient = morpho.myGrad(image, gamma8)

watershed = morpho.watersheds(gradient, marksList, gamma8list)

numberObjects = len(marksList)

watershed = watershed * (255 / (numberObjects + 1))

image = cv2.imread(imagename)
morpho.displayImage("Original image", image)
morpho.displayImage("After Watersheds", watershed)

key = cv2.waitKey(0)