Blackest Pixel - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Blackest Pixel (/Thread-Blackest-Pixel) |
Blackest Pixel - Dirk - 06-09-2019 Hi I'm writing a python script to cleanup a scan text document. (I'll have to cleanup thousands of pages) Is there a way to determine what is the darkest pixel in the image? I want to use "pdb.gimp_image_select_color" using the darkest pixel (which is not always pure black (0, 0, 0)) RE: Blackest Pixel - Ofnuts - 06-10-2019 No direct way as far as I can tell. You can use several calls with Gimp histogram, adjusting the upper limit of the range until you don't get any pixels in the range: The call is: Code: mean, std_dev, median, pixels, count, percentile = pdb.gimp_drawable_histogram(drawable, channel, start_range, end_range) The values you are interested in are count and/or percentile (as far as I can tell, count=pixels*percentile). You use: Code: _,_,_,_, count,_ = pdb.gimp_drawable_histogram(drawable, HISTOGRAM_VALUE, 0.,max) and you try max values (with a dichotomic search you'll never need more than eight calls), something like: Code: def blackest(drawable): However doing a color selection on the result may select a single pixel and may not give you the result you want. What is the whole process? RE: Blackest Pixel - Dirk - 06-10-2019 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): Apologies for my coding style, I'm new to gimp and python. RE: Blackest Pixel - Ofnuts - 06-10-2019 Looks like you are re-inventing the automatic contrast stretch, either Code: pdb.gimp_drawable_levels_stretch(drawable) Also, if you batch-process, using ImageMagick instead of Gimp is likely be a better idea. RE: Blackest Pixel - Dirk - 06-10-2019 Thanks, will look into these. Don't want the re-invent something. Yes, I thought that ImageMagick might be the way to go, when I was looking for an auto de-skew routine, and came across it. Now for a few more sleepless nights, playing with a new program. |