Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I don't understand this picture #32

Open
rmast opened this issue Nov 30, 2021 · 11 comments
Open

I don't understand this picture #32

rmast opened this issue Nov 30, 2021 · 11 comments

Comments

@rmast
Copy link

rmast commented Nov 30, 2021

image

Why would we need so many colors smeared to the bottom right that are not behind the foreground mask?

Those could all be optimized away to facilitate Run Length Encoding.

@MerlijnWajer
Copy link
Collaborator

I agree that in the case of little text this might be overkill. The thought was that it would help compress the images, but it might not have to go down all the way to the bottom.

What would you suggest the foreground looks like to optimise quality and size?

@MerlijnWajer
Copy link
Collaborator

The reason this is done, by the way, is that if we would only fill in the foreground parts and leave the rest black, the compression would (severely) affect the colours in the foreground image. Initially I had something a little different, which would "radiate" the foreground colours in all directions, mixing them in according to other colours in the vicinity (like here https://archive.org/~merlijn/projects/archive-pdf-tools/doc-imgs/alien-mrc-fg.png), but this was quite slow (like, 10-20x slower), and ultimately didn't compress much better, nor give much better quality.

@rmast
Copy link
Author

rmast commented Nov 30, 2021 via email

@MerlijnWajer
Copy link
Collaborator

Right, so the constraints are that it must be encoded in an image format the PDF supports, so no images with custom compression can be embedded. If you can figure out a way to use c44 compression on a mask + input image and create (say) a PNG or TIF file from that, I could look at turning that into a JPEG/JPEG2000 and see if it compresses better or at least provides better quality.

Some JPEG2000 encoders support "region of interest" (ROI) encoding, where they actually take a mask with the region that should be better encoded than other parts, but I tried for days to get that to produce anything sensible, and it never worked well for me.

@rmast
Copy link
Author

rmast commented Nov 30, 2021 via email

@rmast
Copy link
Author

rmast commented Nov 30, 2021

I was looking at the ROI in the documentation https://gist.github.com/ahankinson/494572, and close by in the same part of the manual was another construction: "VIS means visual masking;"

https://ieeexplore.ieee.org/document/901044

@rmast
Copy link
Author

rmast commented Nov 30, 2021

I do not have clear whether this 'masking' allows providing a mask, or is some result of locally interpreting of the provided image.

@rmast
Copy link
Author

rmast commented Nov 30, 2021

One of the writers has 60 patents on his name, however the publication is almost 20 years old.
https://theinformaticists.com/portfolio/debargha-mukherjee/

@MerlijnWajer
Copy link
Collaborator

https://www.researchgate.net/profile/Christos-Chrysafis/publication/3970298_JPEG2000-matched_MRC_compression_of_compound_documents/links/54491d820cf244fe9ea21f60/JPEG2000-matched-MRC-compression-of-compound-documents.pdf?origin=publication_detail

"Because the layer coder employed is wavelet-based
JPEG2000, smoothness guarantees compactness. Pixels are
traversed in raster scan order in each layer, and for each hole
pixel encountered, interpolation is performed by a weighted
averaging with Gaussian weights, in a P ×P sliding window
(where P is typically 5 or 7) centered on it. "

Sounds a bit like what I tried to do initially, and then made a fast approximation for later on (the image in your first post in this issue). Maybe it makes sense to make the background in the foreground image gray, and not black, for more smoothness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants