def prepare_data(self, images, labels=None): if (labels is None): for (i, image) in enumerate(images): number = ("%0.3d" % (i+1)) path_save = path.join(self.dn_test_out, mkdir=True) image, _ = dip.preprocessor(image, None) original_name = (const.fn_PREPROCESSING % (number)) data.imwrite(path.join(path_save, original_name), image) yield self.arch.prepare_input(image) else: for (image, label) in zip(images, labels): (image, label) = dip.preprocessor(image, label) yield self.arch.prepare_input(image), self.arch.prepare_input(label)
def fetch_from_paths(images, labels): image_list, label_list = [], [] for img, lab in zip(images, labels): img_fetch = sorted(glob(path.join(img, const.FILTER))) lab_fetch = sorted(glob(path.join(lab, const.FILTER))) img_fetch, lab_fetch = misc.shuffle(img_fetch, lab_fetch) for i, l in zip(img_fetch, lab_fetch): image_list.append(i) label_list.append(l) image = np.array([cv2.imread(item, 1) for item in image_list]) label = np.array([cv2.imread(item, 1) for item in label_list]) return image, label
def update(self): from os import walk found = [] for directory in self.settings.directories(): if path.exists(directory): for root, dirnames, filenames in walk(directory): for filename in filenames: # Get around the 256 character limit by prepending \\\\?\\ absolute = path.join("\\\?\\", root, filename) if filename.lower().endswith(tuple(self.settings.file_extensions)): mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = stat(absolute) if size > self.settings.minimum_size_byte: found.append(Film(abspath=absolute, last_modification=get_datetime(mtime), size=size)) else: self.settings.directories().remove(directory) # Film has been removed from disk - remove from library for film in self.films: if film not in found: #print('Removed: {}'.format(film.print())) self.films.remove(film) #del film # New film - add to library for film in found: if film not in self.films: #print('Found: {}'.format(film.print())) self.films.append(film)
def tolabel(): dn_tolabel = path.out(const.dn_TOLABEL, mkdir=False) if path.exist(dn_tolabel): dir_save = path.out(const.dn_TOLABEL) images = data.fetch_from_path(dir_save) for (i, image) in enumerate(images): path_save = path.join(dir_save, "label", mkdir=True) file_name = ("%0.3d.png" % (i+1)) file_save = path.join(path_save, file_name) img_pp, _ = dip.preprocessor(image, None) data.imwrite(file_save, img_pp) else: print("\n>> Folder not found (%s)\n" % dn_tolabel)
def save_predict(self, original, image): path_save = path.join(self.dn_test_out, mkdir=True) with open(path.join(path_save, (const.fn_SEGMENTATION)), 'w+') as f: for (i, image) in enumerate(image): number = ("%0.3d" % (i+1)) image_name = (const.fn_PREDICT % (number)) image = dip.posprocessor(original[i], self.arch.prepare_output(image)) data.imwrite(path.join(path_save, image_name), image) seg = (image == 255).sum() f.write(("Image %s was approximately %f segmented (%s pixels)\n" % (number, (seg/image.size), seg))) original_name = (const.fn_ORIGINAL % (number)) data.imwrite(path.join(path_save, original_name), original[i]) overlay_name = (const.fn_OVERLAY % (number)) overlay = dip.overlay(original[i], image) data.imwrite(path.join(path_save, overlay_name), overlay) f.close()
def fetch_from_path(images): image_list = sorted(glob(path.join(images, const.FILTER))) image = np.array([cv2.imread(item, 1) for item in image_list]) return image
def length_from_path(file_dir, *dirs): length_fetch = len(glob(path.join(file_dir, const.FILTER))) for x in dirs: length_fetch += len(glob(path.join(x, const.FILTER))) return length_fetch