Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blackest Pixel
#3
Hi Ofnuts, thanks for taking the time to respond, and moving into right board

We are scanning very old documents, that was still typed using a typewriter. We are scanning it at 600dpi in grayscale. The mission now is to clean-up the scans, and reduce file size as much as possible (300dpi Black and white) to be able to share these documents. Some documents are very bad, with a lot of noise etc.

Pointing me to the histogram, solved my problem.  Based on the percentile I decided to get the range that is used the most in the lower scale of the histogram, and set all pixels up to that scale to black.


Code:
def SetBlack(image, drawable):
    #find the "color" that is used the most in "darker" side of the historgram - this is the black of text
    MaxPercentile = 0.0
    MaxEndRange = 0.0
    Increment = 0.025 #2.5% increase
    
    start_range = 0.0
    end_range = Increment
    mean, std_dev, median, pixels, count, percentile = pdb.gimp_drawable_histogram(drawable, 0, start_range, end_range)
    if percentile > MaxPercentile:
        MaxPercentile = percentile
        MaxEndRange = end_range
    
    for x in range(0, 20):
        start_range = end_range
        end_range = end_range + Increment
        mean, std_dev, median, pixels, count, percentile = pdb.gimp_drawable_histogram(drawable, 0, start_range, end_range)
        if percentile > MaxPercentile:
            MaxPercentile = percentile
            MaxEndRange = end_range
        #pdb.gimp_message(percentile)
    
    MaxEndRange = MaxEndRange * 1.2 #Add 20%
    #pdb.gimp_message(MaxPercentile)
    #pdb.gimp_message(MaxEndRange)
    pdb.gimp_drawable_curves_spline(drawable, 0, 6, (0.0, 0.0, MaxEndRange, 0.0, 0.9, 1.0))


Apologies for my coding style, I'm new to gimp and python.
Reply


Messages In This Thread
Blackest Pixel - by Dirk - 06-09-2019, 09:13 PM
RE: Blackest Pixel - by Ofnuts - 06-10-2019, 09:09 AM
RE: Blackest Pixel - by Dirk - 06-10-2019, 12:44 PM
RE: Blackest Pixel - by Ofnuts - 06-10-2019, 01:33 PM
RE: Blackest Pixel - by Dirk - 06-10-2019, 02:33 PM

Forum Jump: