replace image extraction logic final

This commit is contained in:
Julius Unverfehrt 2023-02-06 09:43:28 +01:00
parent bd0279ddd1
commit 4d43e385c5

View File

@ -148,10 +148,6 @@ def xref_to_image(doc, xref) -> Union[Image.Image, None]:
pixmap = fitz.Pixmap(doc, xref)
array = np.frombuffer(pixmap.samples, dtype=np.uint8).reshape(pixmap.h, pixmap.w, pixmap.n)
array = normalize_channels(array)
print(array.shape)
assert array.shape[-1] == 3
# # TODO: Find a better solution: PIL.Image.fromarray doesn't take grayscale images of the shape (h, w, 1) but (h, w)
# array = array[:, :, 0] if array.shape[2] == 1 else array
return Image.fromarray(array)
except ValueError:
logger.debug(f"Xref {xref} is invalid, skipping extraction ...")