Sign up now! · Forgot password?
RSS/Atom feed identi.ca Twitter

threshold function parameters that vary by position? (going to B&W from a book page photo)

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

Nick LaForge
2012-04-01 03:44:39 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Hello,

I would like to obtain a black and white image of a photograph of a book page.

My attempt to do this is by running the threshold function over the entire image. This appears to give the desired result, but only locally. It appears that the optimum parameters of the threshold function vary by position (i.e., according to some scalar field), with one extreme in the center of the glare and then radiating outward. So just running the threshold function over the entire image with constant parameters always gives sub-optimum contrast for 75% of the image. Will I have to find a way to run the threshold function with non-constant parameters, or is there some other tool to do the job?

Thanks for reading, Nick

Nick LaForge
2012-04-01 03:53:03 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Hello,

I would like to obtain a black and white image of a photograph of a book page.

My attempt to do this is by running the threshold function over the entire image. This appears to give the desired result, but only locally. It appears that the optimum parameters of the threshold function vary by position (i.e., according to some scalar field), with one extreme in the center of the glare and then radiating outward. So just running the threshold function over the entire image with constant parameters always gives sub-optimum contrast for 75% of the image. Will I have to find a way to run the threshold function with non-constant parameters, or is there some other tool to do the job?

Thanks for reading, Nick

Francesco Scaglioni
2012-04-01 04:08:11 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Just a thought : could you apply a gradient to a new layer to correct for the variation then apply the threshold tool to a "new from visible"? ---
(Apologies for brevity, top posting and poor citation - this email was sent from a mobile device) ---

-----Original Message----- From: Nick LaForge
Sender:
Date: Sat, 31 Mar 2012 19:53:03
To:
Subject: [Gimp-user] threshold function parameters that vary by position? (going to B&W from a book page photo)

Hello,

I would like to obtain a black and white image of a photograph of a book page.

My attempt to do this is by running the threshold function over the entire image. This appears to give the desired result, but only locally. It appears that the optimum parameters of the threshold function vary by position (i.e., according to some scalar field), with one extreme in the center of the glare and then radiating outward. So just running the threshold function over the entire image with constant parameters always gives sub-optimum contrast for 75% of the image. Will I have to find a way to run the threshold function with non-constant parameters, or is there some other tool to do the job?

Thanks for reading, Nick

Owen
2012-04-01 04:19:42 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Hello,

I would like to obtain a black and white image of a photograph of a book page.

My attempt to do this is by running the threshold function over the entire image. This appears to give the desired result, but only locally. It appears that the optimum parameters of the threshold function vary by position (i.e., according to some scalar field), with one extreme in the center of the glare and then radiating outward. So just running the threshold function over the entire image with constant parameters always gives sub-optimum contrast for 75% of the image. Will I have to find a way to run the threshold function with non-constant parameters, or is there some other tool to do the job?

Without seeing the image, one can only suggest you try converting the image to Indexed and 2 colors.

You could also leave it as rgb and play with the curves, maybe one of the colors can be filtered out.

If you get a good B & W image, you might then want to run it through the unsharp mask to improve the text.

-- Owen

Nick LaForge
2012-04-01 06:32:58 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Thanks for the replies. I've uploaded the original image, along with three modified images that are satisfactory at various distances along my imaginary gradient.

original: http://lh5.googleusercontent.com/-zw3ICTEiurs/T3fwShHiK8I/AAAAAAAAAKU/fTTWnYCJyZA/s575/original.jpg

contrast applied with increasing upper levels parameter and minimal gamma (no gray)::
http://lh6.googleusercontent.com/-Vc0C2KcpOAw/T3fwSLBrexI/AAAAAAAAAK4/9AEbK7qyBHc/s771/1.JPG http://lh5.googleusercontent.com/-6x8X75cw4JI/T3fwSmRcODI/AAAAAAAAAKY/LfRwru-LQQg/s771/2.JPG http://lh4.googleusercontent.com/-48qQsSkULZU/T3fwSJMN5pI/AAAAAAAAAKI/r5AdxIcFvb0/s771/3.jpg

You can see from the trend that there does exist a set of parameters for the threshold function that gives acceptable contrast for every given point, and that this one parameter (the upper level) increases monotonically as it moves along the "vector field".

Regarding the suggestions: I think I've played with levels enough without results. On the other hand, I don't know about the layer mask approach. From my limited abilities, I can only see that layer masks modulate the opacity of the resulting image after having applied some filter to a duplicate layer, whereas I want to modulate the input parameters of a "filter" (threshold) to the original layer.

Sorry if I'm making this more complicated than necessary, and thanks for reading.

-Nick

On 3/31/12, Owen wrote:

Hello,

I would like to obtain a black and white image of a photograph of a book page.

My attempt to do this is by running the threshold function over the entire image. This appears to give the desired result, but only locally. It appears that the optimum parameters of the threshold function vary by position (i.e., according to some scalar field), with one extreme in the center of the glare and then radiating outward. So just running the threshold function over the entire image with constant parameters always gives sub-optimum contrast for 75% of the image. Will I have to find a way to run the threshold function with non-constant parameters, or is there some other tool to do the job?

Without seeing the image, one can only suggest you try converting the image to Indexed and 2 colors.

You could also leave it as rgb and play with the curves, maybe one of the colors can be filtered out.

If you get a good B & W image, you might then want to run it through the unsharp mask to improve the text.

-- Owen

Steve Kinney
2012-04-01 16:20:41 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

On 04/01/2012 02:32 AM, Nick LaForge wrote:

You can see from the trend that there does exist a set of parameters for the threshold function that gives acceptable contrast for every given point, and that this one parameter (the upper level) increases monotonically as it moves along the "vector field".

Something to try:

1) Run the Colors > Auto > Equalize filter against your image.

2) Then use the Colors > Curves tool, setting the "left" value at 0 and the "right" value at 255, to create a very steep, nearly vertical "curve." Move this back and forth until you come close to the finished appearance you want.

3) Finally, run the threshold tool.

This method first increases contrast in low contrast areas while reducing it in high contrast areas ("Equalize"), then allows you to do a more-than-one-color threshold effect that adds or removes values near the threshold for a two color conversion ("Curves") and finally the Threshold tools gives you a two color map.

YMMV, there are so many ways, etc. etc.

:o)

Steve

Rob Antonishen
2012-04-01 18:21:29 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Regarding the suggestions: I think I've played with levels enough without results. On the other hand, I don't know about the layer mask approach. From my limited abilities, I can only see that layer masks modulate the opacity of the resulting image after having applied some filter to a duplicate layer, whereas I want to modulate the input parameters of a "filter" (threshold) to the original layer.

Here is the way I compensate for such exposure when you know the background should all be one colour:

1) Duplicate your source layer. 2) Select the duplicate layer and run Filters->Generic-> Dilate. 3) Repeat the dilate (ctrl-f) until the (black) print is gone. (For your sample I did it three times)
4) Apply a larger radius Gaussian blur (10 times the number of dilates you did seems to work for me, so in this case, 30px) 5) This layer is kind of a low-pass filter version of your page with the text removed. Set this layer to grain extract to kind of remove it from the original.
6) Do Layer->New from Visible to get the composite. 7) Now go and play with levels/curves/thresholding.

Note this works best with low noise images (i.e. tiff or png is better than jpeg) and higher resolution scans...

Here is what I ended up with: http://www.majhost.com/gallery/ffaat/gimp/more2/results.jpg

-Rob A>

Nick LaForge
2012-04-01 19:00:47 UTC (over 2 years ago)

threshold function parameters that vary by position? (going to B&W from a book page photo)

Here is the way I compensate for such exposure when you know the background should all be one colour:

1) Duplicate your source layer. 2) Select the duplicate layer and run Filters->Generic-> Dilate. 3) Repeat the dilate (ctrl-f) until the (black) print is gone. (For your sample I did it three times)
4) Apply a larger radius Gaussian blur (10 times the number of dilates you did seems to work for me, so in this case, 30px) 5) This layer is kind of a low-pass filter version of your page with the text removed. Set this layer to grain extract to kind of remove it from the original.
6) Do Layer->New from Visible to get the composite. 7) Now go and play with levels/curves/thresholding.

Note this works best with low noise images (i.e. tiff or png is better than jpeg) and higher resolution scans...

Here is what I ended up with: http://www.majhost.com/gallery/ffaat/gimp/more2/results.jpg

-Rob A>

Thanks, this method gives virtually perfect results. Also, thanks to everyone for writing your suggestions.

I like how the generality of the "grain extract" and its siblings would seem to make it a powerful tool in a number of areas, and I'm now fascinated. :-) I wonder if there exists a sort of compendium of gimp techniques from the signal processing perspective....

Nick