def pipeline(filename, temp_dir): """ Convenient wrapper around the feature extraction pipeline """ x = plt.imread(filename)[:,:,0] cropped = process_image(x) to_save = filename.split('.')[0] + '.png' plt.imsave(os.path.join(temp_dir, to_save), cropped, cmap=plt.cm.gray)
def test_defective_images(self): """ Assert that the images in the defective list are indeed defective. """ with open(self.defects, 'r') as f: defects_list = json.load(f) defects = [f[0] for f in defects_list] isError = [] for defect in defects: path = os.path.join(ROOT, 'images_training',defect) try: x = plt.imread(path) cropped = process_image(x) save_path = os.path.join(self.processed_path, defect) plt.imsave(save_path, cropped, cmap=plt.cm.gray) except: isError.append(True) self.assertTrue(all(isError))