make all pixels below a certain threshold white? [solved]

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
BradLee
Posts: 23
Joined: 2017-04-11T05:09:01-07:00
Authentication code: 1151

make all pixels below a certain threshold white? [solved]

Post by BradLee »

Hi,

I'm trying to make all white pixels below a certain threshold white.
I scanned some pages from a book and there are some not-quite-white pixels, that I want to make true white.

I can do this in another image app by using the wand tool with a 20% threshold, then cutting everything and pasting it onto a clean white page.

But I need to do it on a large number of images, so I am hoping to batch process it with IM instead.

Using ImageMagick-7.0.5-4-Q16-x64-dll.exe In Windows 7.

Kind regards,

Brad

EDIT: Essentially what I am doing is cutting the text off of a page and pasting it onto a white page if that makes more sense.
Last edited by BradLee on 2017-04-18T05:24:45-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: make all pixels below a certain threshold white?

Post by fmw42 »

Are you sure you do not want to make all pixels above a certain graylevel into white to even out all the (near-) white areas. If that is the case, then try

Code: Select all

magick image -white-threshold XX% result
Where XX% is the percent graylevel value near white. So 80% would make gray(80%) and above into pure white.

If this is not what you want, then please post an example image to some place such as dropbox.com and put the URL here and explain what regions you want white.
BradLee
Posts: 23
Joined: 2017-04-11T05:09:01-07:00
Authentication code: 1151

Re: make all pixels below a certain threshold white?

Post by BradLee »

fmw42 wrote: 2017-04-15T20:39:48-07:00 Are you sure you do not want to make all pixels above a certain graylevel into white to even out all the (near-) white areas.
But isn't white 0, and black 255?

Anyhow, your suggestion of this works:

Code: Select all

magick image -white-threshold XX% result
fmw42 wrote: 2017-04-15T20:39:48-07:00 If this is not what you want, then please post an example image to some place such as dropbox.com and put the URL here and explain what regions you want white.
That is what I wanted, thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: make all pixels below a certain threshold white?

Post by fmw42 »

But isn't white 0, and black 255?
White is gray(100%) or gray(255) or gray100. Black is gray(0%) or gray(0) or gray0.
BradLee
Posts: 23
Joined: 2017-04-11T05:09:01-07:00
Authentication code: 1151

Re: make all pixels below a certain threshold white?

Post by BradLee »

I was referring to absolute white and black, but nevermind it seems that I have mixed the two up.

Black being #000, white being #FFF
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: make all pixels below a certain threshold white?

Post by fmw42 »

BradLee wrote: 2017-04-15T21:10:16-07:00 I was referring to absolute white and black, but nevermind it seems that I have mixed the two up.

Black being #000, white being #FFF
The above hex values are correct.

Do you mean opacity vs transparency? If you have an alpha channel, white will correspond to fully opaque and black will correspond to fully transparent.
BradLee
Posts: 23
Joined: 2017-04-11T05:09:01-07:00
Authentication code: 1151

Re: make all pixels below a certain threshold white?

Post by BradLee »

@fmw42,

As I already explained, I had the white and black values mixed up the wrong way around.
In my mind I thought that WHITE was #000, and BLACK was #FFF
Post Reply