Closed jboarman closed 3 years ago
I tested several implementations of halftone and i think this is the best and closest to the example above:
Example of the other implementation:
What do you guys think?
@kwcckw I concur with your assessment. Your suggestion looks good.
I’m assuming the Phaxio implementation is tweaked for the low resolution of a fax machine, which is why their output differs.
It seems to favor a straight monochrome effect, instead of halftone, for near black values. You should be able to emulate that effect by forcing the pixels to true black that are within some threshold prior to halftoning the image.
If the halftone effect messes with true black, then you will have to separate pixels that are near black into a separate matrix and overlay them on top of the halftone output.
It seems to favor a straight monochrome effect, instead of halftone, for near black values. You should be able to emulate that effect by forcing the pixels to true black that are within some threshold prior to halftoning the image.
Right, but the question would be are we gonna do that in our augmentation too? Although it looks better in that way.
If the halftone effect messes with true black, then you will have to separate pixels that are near black into a separate matrix and overlay them on top of the halftone output.
Yes, i will try that and check again whether it is better, thanks.
We'll probably need it in more places, so I put a binaryThreshold
function in augmentations/lib.py
that takes an image and a cv2.THRESH_ value (defaults to Otsu), makes the image grayscale, then applies the threshold.
(I also forgot to pre-commit install
in my new development container, so I originally pushed a non-PEP8-compliant commit. See how important it is to have pre-commit hooks? :grin: )
We'll probably need it in more places, so I put a
binaryThreshold
function inaugmentations/lib.py
that takes an image and a cv2.THRESH_ value (defaults to Otsu), makes the image grayscale, then applies the threshold.
Okay, we would need several thresholding methods so i gonna edit that section again if needed.
Completed with PR #87
Real faxed example with lots of dithering
Here are the effects that a faxed document experiences:
The resolution should be assumed to have already been normalized (to 300 DPI) in advance of calling this augmentation, OR the source resolution could be provided as a parameter so that proper scaling can be calcutated to a convert to 200 DPI. Will may need to re-scale it back to the source resolution (after being downsampled) so that other augmentations, that rely on a normalized resolution, can be applied after this augmentation has been applied.
Phaxio has a short and simple article showing the difference in thresholded ("monochrome") vs halftoned faxes.
Thresholding basics are covered in this OpenCV Tutorial.
Example PDFs (from Phaxio):
original.pdf monochrome.pdf halftone.pdf