def extract_patches(path, max_patches, patch_size): """ Extract a patch of images of the same `patch_size` from the original image. Output is a 4D-Numpy array with shape (max_patches, *patch_size, num_channels=3). """ img = cv2.imread(path) img = np.expand_dims(img, axis=0) patch_extractor = PatchExtractor(max_patches=max_patches, patch_size=patch_size) patch_extractor.fit(img) return patch_extractor.transform(img)
def test_patch_extractor_fit(): faces = face_collection extr = PatchExtractor(patch_size=(8, 8), max_patches=100, random_state=0) assert extr == extr.fit(faces)
def test_patch_extractor_fit(): faces = face_collection extr = PatchExtractor(patch_size=(8, 8), max_patches=100, random_state=0) assert_true(extr == extr.fit(faces))
def test_patch_extractor_fit(): lenas = lena_collection extr = PatchExtractor(patch_size=(8, 8), max_patches=100, random_state=0) assert_true(extr == extr.fit(lenas))