Exemple #1
0
 def Merge(self, im):
     h, w = np.shape(im)
     merged = np.zeros((h, w, 3))
     lbp = self.LBP.describe(im)
     grad = self.Grad.getGradientSum(im)
     if self.equalize:
         im = cv2.equalizeHist(im)
         lbp = cv2.equalizeHist(lbp)
         grad = cv2.equalizeHist(grad)
     if self.testMode:
         moil.show(im, other_im=[lbp, grad])
     merged[:, :, 0] = im
     merged[:, :, 1] = lbp
     merged[:, :, 2] = grad
     return merged.astype('uint8')
Exemple #2
0
def square_circle_on_1_2_in_path(path):
    for i in range(6):
        im, im_cp = moil.read_and_size_with_copy(str(i), path=path, scale=0.2)

        im = equalize_border_with_mean_or_val(im)

        h, w = np.shape(im)
        r = (int)(h / 8)
        img_sqd = square_circle_difference_filter_2d(im, r)
        # img_sqd = square_circle_minus_filter_2d(im, r)
        # img_sqd = circle_filter_2d(im)

        img_sqd = cv2.equalizeHist(img_sqd)

        ret, imt = cv2.threshold(img_sqd, 250, 255, cv2.THRESH_BINARY)
        cv2.imshow('win2', im_cp)
        cv2.imshow('win32', img_sqd)
        moil.show(imt)
        '''imt2,cnt, hier = cv2.findContours(imt, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
Exemple #3
0
 def MergeOnPath(self, path):
     for i in range(len(os.listdir(path)) - 1):
         img = moil.read_and_size(str(i), path=path, scale=0.3)
         merged = self.Merge(img)
         moil.show(merged, other_im=[img])
Exemple #4
0
    def circle_mask_on_random_image_in_path(self,
                                            path,
                                            target_size=None,
                                            r=None,
                                            extension=".jpg",
                                            check_csv=True,
                                            list=None):

        numb = len([
            i for i in os.listdir(path)
            if os.path.isfile(os.path.join(path, i))
        ])
        temp = ([
            a for a in os.listdir(path)
            if os.path.isfile(os.path.join(path, a))
        ])
        try:
            j = np.random.randint(numb)
        except:
            print(path + ", numb: " + str(numb))
            return

        ImName = random.choice(temp)
        if not os.path.exists(path + '/mask'):
            os.makedirs(path + '/mask')
        tempName = path + '/mask/' + ImName
        if os.path.exists(tempName):
            print("Path exists (" + tempName + ")")
            return
        if check_csv:
            paths = morn.getRepoPathAndImagePath(path)
            row = paths[1].split("/")[:-1]
            row.append(ImName)
            if mocl.checkIfExistsInCSV(row, paths[0], list, False):
                print("In CSV exists (" + tempName + ")")
                return

        if r is None and target_size is not None:
            self.rr = int(target_size[0] / 10)
        else:
            self.rr = r

        img = moil.read_and_size(ImName,
                                 path=path,
                                 target_size=target_size,
                                 extension='')
        w, h, c = moil.getWidthHeightChannels(img)
        if r is None and target_size is None:
            self.rr = int(w / 10)
            target_size = (w, h)
        moil.show(img)

        accepted = False
        while not accepted:
            accepted = True

            im2, contours, hierarchy = cv2.findContours(
                self.mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            im2 = copy.deepcopy(img)
            cv2.drawContours(im2, contours, 0, (0, 255, 255), 2)

            moil.show(im2)

        split_path = path.split("/")[:-1]

        repo_path = reduce((lambda x, y: x + '/' + y),
                           split_path[:len(split_path) - 3])
        if not os.path.isfile(repo_path + "/maskData.csv"):
            csvFile = open(repo_path + '/maskData.csv', 'w', newline="")
            writer = csv.writer(csvFile)
            writer.writerow([
                'patient', 'date', 'eye', 'name', 'width', 'height', 'x', 'y',
                'r'
            ])
            csvFile.close()

        csvFile = open(repo_path + '/maskData.csv', 'a', newline="")
        writer = csv.writer(csvFile)
        ls = split_path[-3:]
        ls.extend([
            ImName, target_size[0], target_size[1], self.xx, self.yy, self.rr
        ])
        writer.writerow(ls)
        csvFile.close()
        cv2.imwrite(path + '/mask/' + ImName, self.mask)
        self.masks_done += 1
        print("masks: " + str(self.masks_done))
        cv2.destroyWindow('mask')
Exemple #5
0
import cv2
import Code.Libraries.MyOculusImageLib as moil
import Code.Libraries.MyOculusRepoNav as morn
import os
path = '../../../Images/ZanikGray50/'

dict = {}

while True:
    im_path = morn.next_path(path, dict)

    dict[im_path] = True
    if not os.path.exists(im_path):
        continue
    ims = os.listdir(im_path)
    for im in ims:
        if not os.path.isfile(im_path + im):
            continue
        img = moil.read_and_size(name=im, path=im_path, scale=1, extension='')
        img2 = cv2.equalizeHist(img)
        moil.show(img, other_im=[img2])
Exemple #6
0
 def model_show_function(x):
     y = []
     for i in range(len(x) - 1):
         y.append(x[i + 1])
     moil.show(x[0], other_im=y)
 def LbpOnPath(self, path):
     for i in range(len(os.listdir(path)) - 1):
         img = moil.read_and_size(str(i), path=path, scale=self.scale)
         lbp = self.describe(img)
         moil.show(lbp, other_im=[img])
Exemple #8
0
 def GradientSumOnPath(self, path):
     for i in range(len(os.listdir(path)) - 1):
         img = moil.read_and_size(str(i), path=path, scale= self.scale)
         grad = self.getGradientSum(img)
         moil.show(grad, other_im=[img])