Advised way to extract text from Text blocks and Image blocks and combine them #2465
Unanswered
JawaClass
asked this question in
Looking for help
Replies: 1 comment 2 replies
-
Your matrix indeed performs an up-down flip (plus different scalings in x- / y-direction). Once you have your PIL image, you therefore need information on which of the many available Pillow transformations to use, right? This works via the Here is a little utility function which should help you with this. In [1]: import fitz
In [2]: from matrix_property import matprop, piltrans
In [3]: mat = fitz.Matrix(245.6999969482422, 0.0, -0.0, -206.60000610351562, 13
...: 6.7906036376953, 378.3905944824219)
In [4]: matprop(mat) # just to show that it detects the transformation
Out[4]: (2, 'up-down')
In [5]: piltrans(mat) # determines the Pillow transformation method
Out[5]: <Transpose.FLIP_TOP_BOTTOM: 1>
In [6]: # if pil_image is your Pillow image, do this to make a transformed copy:
In [7]: trans = piltrans(mat)
In [8]: pil_transformed = pil_image.transform(trans) Please don't hesitate to come back with more questions. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have problems understanding the transformation matrix. For people not good at math its very hard and I couldnt find an example in the documentation where its shown how to apply the transform value to the image to retrive the rendered image.
Bascially I have a image on my PDF that when converting the byte string to an PIL image its shown flipped horizontally and rotated 180° (I read that can happen due to the way the PDF creatore software converts image because no way the user created a flipped image).
It has the following transform matrix:
(245.6999969482422, 0.0, -0.0, -206.60000610351562, 136.7906036376953, 378.3905944824219)
After applying this its shown correctly and how its presented on the PDF page.
I tried to transform the image with PIL affine transformation but transformed_image.show() ends up showing a black image with a bit of white on the top:
Help would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions