Convert color bmp always to White & Black not to B&W
Convert color bmp always to White & Black not to B&W
Hi,
to convert a color bitmap to 1-bit (black&white) bmp is simple,
per example in php environment:
@system('convert -colorspace gray -monochrome -depth 1 ' . $sourceColorBmp . ' ' . $oneBitBmp);
I need some help to convert diverse color bitmaps (with dark or light background) to "1-bit" - but always WHITE & black bitmap,
viz. the background of converted "1-bit" image must be always white, the foreground must be always black
Here are two examples for color bitmaps (source) i need to convert in 1-bit images with WHITE background & black foreground:
1. Bitmap with light background: http://bogx.de/media/20701-2756.bmp
2. Bitmap with dark background: http://bogx.de/media/20701-2757.bmp
Best regards,
Konrad
to convert a color bitmap to 1-bit (black&white) bmp is simple,
per example in php environment:
@system('convert -colorspace gray -monochrome -depth 1 ' . $sourceColorBmp . ' ' . $oneBitBmp);
I need some help to convert diverse color bitmaps (with dark or light background) to "1-bit" - but always WHITE & black bitmap,
viz. the background of converted "1-bit" image must be always white, the foreground must be always black
Here are two examples for color bitmaps (source) i need to convert in 1-bit images with WHITE background & black foreground:
1. Bitmap with light background: http://bogx.de/media/20701-2756.bmp
2. Bitmap with dark background: http://bogx.de/media/20701-2757.bmp
Best regards,
Konrad
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert color bmp always to White & Black not to B&W
Your images have more then two colour (they are aliased). So what do you really want to happen?
What defines the background colour?
What version of IM do you use? On what platform?
What defines the background colour?
What version of IM do you use? On what platform?
snibgo's IM pages: im.snibgo.com
Re: Convert color bmp always to White & Black not to B&W
Hi Snibgo,
yes, the source (input) bitmap files have 24 BitsPerPixel with aliasing.
but desired quality of output files is low, very low, per example:
http://bogx.de/media/20670-2615_1bit.bmp
http://bogx.de/media/20672-2627_1bit.bmp
All input multicolor files (whatever their background color is - dark or light) should convert to white background and black foreground (text, icon, frame).
-----------------------
platform = Linux
API = php 5.6.3
libmagic = 517
-----------------------
Best regards,
Konrad
yes, the source (input) bitmap files have 24 BitsPerPixel with aliasing.
but desired quality of output files is low, very low, per example:
http://bogx.de/media/20670-2615_1bit.bmp
http://bogx.de/media/20672-2627_1bit.bmp
All input multicolor files (whatever their background color is - dark or light) should convert to white background and black foreground (text, icon, frame).
-----------------------
platform = Linux
API = php 5.6.3
libmagic = 517
-----------------------
Best regards,
Konrad
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Convert color bmp always to White & Black not to B&W
The basic problem is trivial, eg:
But the result might need to be negated. How do you define "background"?
Code: Select all
convert 20701-2756.bmp -colorspace Gray -threshold 50% out.png
snibgo's IM pages: im.snibgo.com
Re: Convert color bmp always to White & Black not to B&W
background is always homogeneous color (no gradient or color mix),
foreground is text, or text and icon or text, icon and frame - all of those always the same color.
per example:
Input files
1. input1.bmp: background = color1 (dark), foreground = color2 (light)
2. input2.bmp: backgrond = color3 (light), foreground = color4 (dark)
output files
ad 1. output1.bmp should be: background = white, foreground = black
ad 2. output2.bmp should be: background = white, foreground = black
foreground is text, or text and icon or text, icon and frame - all of those always the same color.
per example:
Input files
1. input1.bmp: background = color1 (dark), foreground = color2 (light)
2. input2.bmp: backgrond = color3 (light), foreground = color4 (dark)
output files
ad 1. output1.bmp should be: background = white, foreground = black
ad 2. output2.bmp should be: background = white, foreground = black
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
What you want to do is make a binary image as snibgo suggested. Then blur it slightly to anti-alias the edges.
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result.png
Re: Convert color bmp always to White & Black not to B&W
Hi fmw42,
the result in your code must be "png" file?
I have changed "result.png" in "result.bmp":
but the result was completely black bitmap.
Is it easier to get input file as "png" also? For input I have both: png & bmp.
My result must be 1-bit "bmp" file (not a "png" image file) ...
Best, Konrad
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result.png
I have changed "result.png" in "result.bmp":
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result.bmp
Is it easier to get input file as "png" also? For input I have both: png & bmp.
My result must be 1-bit "bmp" file (not a "png" image file) ...
Best, Konrad
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
Looks fine to me using
and then (unix)
display result.bmp
What is your IM version? What viewer are you using? Perhaps the viewer needs a BMP3: or BMP2: image format
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result.bmp
display result.bmp
What is your IM version? What viewer are you using? Perhaps the viewer needs a BMP3: or BMP2: image format
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% BMP3:result.bmp
Code: Select all
convert 20701-2757.bmp -colorspace Gray -auto-level -threshold 50% -blur 0x1 -level 0x50% BMP2:result.bmp
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
If in a .bat file, then % needs to be doubled to %%.
Re: Convert color bmp always to White & Black not to B&W
My IM Version:
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-09-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib
Viewer ist "IrfanView 64"
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-09-23 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib
Viewer ist "IrfanView 64"
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
Did you try my BMP3: or BMP2: commands? What viewer are you using to look at your results. My command works fine for me on IM 6.9.7.9 Q16 Mac OSX.
Re: Convert color bmp always to White & Black not to B&W
is my IM 6.8.9-9 out-dated?
My viewer is "IrfanView"
My viewer is "IrfanView"
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
IM 6.8.9.9 should be OK. But check the changelog for changes to BMP. I suspect that your Irfanviewer is not liking BMP 4 with 1-bit.
See http://legacy.imagemagick.org/script/changelog.php
See http://legacy.imagemagick.org/script/changelog.php
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert color bmp always to White & Black not to B&W
Perhaps another IM Windows user can double check my command and view the results. I am not a Windows user.
Re: Convert color bmp always to White & Black not to B&W
Sorry, but this make me confused:
I made on my linux-server now a simple php file with 2 lines for test:
exec('convert 20701-2756.bmp convert -colorspace gray -monochrome -depth 1 result_1.bmp');
exec('convert 20701-2756.bmp -colorspace gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result_2.bmp');
Result:
line 1 works
line 2 dont works - no file (result_2.bmp) is created
My IM is maybe not up to date?
I made on my linux-server now a simple php file with 2 lines for test:
exec('convert 20701-2756.bmp convert -colorspace gray -monochrome -depth 1 result_1.bmp');
exec('convert 20701-2756.bmp -colorspace gray -auto-level -threshold 50% -blur 0x1 -level 0x50% result_2.bmp');
Result:
line 1 works
line 2 dont works - no file (result_2.bmp) is created
My IM is maybe not up to date?