Exemple #1
0
    def createImagesInRepoAfterFunctionOnPath(self,
                                              path,
                                              new_repo_path,
                                              function,
                                              target_size,
                                              override=False,
                                              extension='.jpg',
                                              onlyMasked=False):
        success = 0
        fail = 0
        repo_path, image_path = morn.getRepoPathAndImagePath(path)

        base2, name2 = BuildRepo.getBaseRepoPathAndRepoName(new_repo_path)
        BuildRepo.createImagesRepo(base2 + '/', name2)
        new_path = new_repo_path + image_path

        maskList = None
        if onlyMasked:
            maskList = mocl.getCsvList(repo_path, False)

        for a in os.listdir(path):
            if not os.path.isfile(os.path.join(path, a)):
                continue
            patient, date, eye = morn.getPatientDateEye(image_path)

            if onlyMasked and not os.path.isfile(
                    os.path.join(path + 'mask/', a)
            ) and not mocl.checkIfExistsInCSV(
                [patient, date, eye, a], list=maskList, image=False):
                continue
            name = a.split(".")[0]
            base_image = moil.read_and_size(name,
                                            path=path,
                                            target_size=target_size)
            image = function(base_image)

            if morn.createImageInPath(new_path, name + extension, image,
                                      override):
                mocl.registerImageCsv(new_repo_path, image_path,
                                      name + extension, image, function)
                success += 1
            else:
                fail += 1
        return success, fail
Exemple #2
0
    def callback(self):

        filename = filedialog.askopenfilename(title="Select file",
                                              filetypes=(("all files", "*.*"),
                                                         ("jpeg files",
                                                          "*.jpg")))

        # filename = easygui.fileopenbox()
        self.root.update()
        if filename == '':
            return
        img = moil.read_and_size(name='', path=filename, extension='')
        self.currentImg = img
        self.x = -1
        self.y = -1
        self.atrophyRate = -1
        self.distance = -1
        self.xOut = -1
        self.yOut = -1
        self.predicted = False
        self.path = filename
        self.label.configure(
            text="Stopień zaniku (tylko faza tętniczo-żylna): ")
        self.updateGuiImage(img)
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])
 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 #7
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])