Imagemagick and converting to monochrome bitmaps
Imagemagick and converting to monochrome bitmaps
Before I get to the problem, i would first like to say hello as I just registered and am posting my first thread.
Ok. Now to the ugly stuff. I'm running ImageMagick 6.6.8-5 Q16 on Arch Linux 64-bit. I can't get any decent pics by using convert to convert colored or grayscale images to xbm or similar formats. Can you suggest any options for interpolation and mono dithering. I wish the result is at least fixable with a bitmap editor.
Image 1: Sample conversion original vs GIMP vs IM
Actually looking now at the uploaded image, it seems IM does a decent job, but black background is ruining it...
Second problem is with xbm images. Converting monochrome xpm icons to xbm creates an ugly black background. Is it possible to (instead) create two files from the original: one for the image and one for the mask? Also, it seems that GIMP exports xbm with white background. How would I achieve that with IM?
Image 2: Example how GIMP exports xpm image to xbm + mask:
Image 3: Example how IM handles the same conversion:
I'm having this problems occuring repeatedly from time to time. For everything else, IM seems to be perfect graphic manipulation package and I've used it numerous times both in shell scripts and on command line.
Thank you in advance.
Ok. Now to the ugly stuff. I'm running ImageMagick 6.6.8-5 Q16 on Arch Linux 64-bit. I can't get any decent pics by using convert to convert colored or grayscale images to xbm or similar formats. Can you suggest any options for interpolation and mono dithering. I wish the result is at least fixable with a bitmap editor.
Image 1: Sample conversion original vs GIMP vs IM
Actually looking now at the uploaded image, it seems IM does a decent job, but black background is ruining it...
Second problem is with xbm images. Converting monochrome xpm icons to xbm creates an ugly black background. Is it possible to (instead) create two files from the original: one for the image and one for the mask? Also, it seems that GIMP exports xbm with white background. How would I achieve that with IM?
Image 2: Example how GIMP exports xpm image to xbm + mask:
Image 3: Example how IM handles the same conversion:
I'm having this problems occuring repeatedly from time to time. For everything else, IM seems to be perfect graphic manipulation package and I've used it numerous times both in shell scripts and on command line.
Thank you in advance.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Imagemagick and converting to monochrome bitmaps
post a link to you original image and supply your exact command line.
Note your uploaded image 1 is rather strangely named as: screenshot0324201102012.th.png.jpeg
So was that supposed to be png or jpeg?
I had no trouble converting your image 1 to xbm or xpm on IM 6.6.8.6 Q16 Max OSX tiger and view with IM X11 display.
Note your uploaded image 1 is rather strangely named as: screenshot0324201102012.th.png.jpeg
So was that supposed to be png or jpeg?
I had no trouble converting your image 1 to xbm or xpm on IM 6.6.8.6 Q16 Max OSX tiger and view with IM X11 display.
Re: Imagemagick and converting to monochrome bitmaps
The original images:
http://www.bojanpopovic.com/downloads/a ... -48x48.png
http://www.bojanpopovic.com/downloads/folder1.xpm
First picture is a traditional Arch Linux logo taken as an example of colour to mono conversion. The second picture is from my icon set inspired by monochrome Mac Classic icon set.
or in the first case
http://www.bojanpopovic.com/downloads/a ... -48x48.png
http://www.bojanpopovic.com/downloads/folder1.xpm
First picture is a traditional Arch Linux logo taken as an example of colour to mono conversion. The second picture is from my icon set inspired by monochrome Mac Classic icon set.
Imageshack (image host) uses jpg for thumbnails. But if you click on the image, you get the original: http://img842.imageshack.us/i/screensho ... 02012.png/.fmw42 wrote:So was that supposed to be png or jpeg?
And what result did you get? Not a problem if it would or would not convert, but rather of quality of conversion. Btw, I was using rather generic:fmw42 wrote:I had no trouble converting your image 1 to xbm or xpm on IM 6.6.8.6 Q16 Max OSX tiger and view with IM X11 display.
Code: Select all
convert image.xpm image.xbm
Code: Select all
convert image.png image.xbm
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Imagemagick and converting to monochrome bitmaps
Your folder1.xpm has transparency. When converted to xbm it loses transparency which becomes black.
I even tried
convert folder1.xpm -channel rgba -alpha on folder1.xbm
but transparency was lost. Perhaps xbm does not support transparency. see http://en.wikipedia.org/wiki/X_BitMap
Your image arch_old-48x48.png also contains transparency. So I get the same loss of transparency when converted to xbm. However when converted to xpm it looks the same as the original.
I even tried
convert folder1.xpm -channel rgba -alpha on folder1.xbm
but transparency was lost. Perhaps xbm does not support transparency. see http://en.wikipedia.org/wiki/X_BitMap
Your image arch_old-48x48.png also contains transparency. So I get the same loss of transparency when converted to xbm. However when converted to xpm it looks the same as the original.
Re: Imagemagick and converting to monochrome bitmaps
Thank you. That partially solved the problem. I replaced the alpha color with white in an image editor and it worked. Is there a way to do this automatically with IM (convert alpha to white)? Or I should do that (as a pre-step) with original images before converting to monochrome?
Re: Imagemagick and converting to monochrome bitmaps
Maybie it would help to post the output of identify on folder1.xpm
Strangely, IM doesn't recognize transparent color though.
Code: Select all
Image: folder1.xpm
Format: XPM (X Windows system pixmap (color))
Class: DirectClass
Geometry: 32x32+0+0
Resolution: 72x72
Print size: 0.444444x0.444444
Units: Undefined
Type: Bilevel
Base type: Bilevel
Endianess: Undefined
Colorspace: RGB
Depth: 16/1-bit
Channel depth:
gray: 1-bit
alpha: 1-bit
Channel statistics:
Gray:
min: 0 (0)
max: 65535 (1)
mean: 28287.6 (0.431641)
standard deviation: 32459.8 (0.495305)
kurtosis: -1.92381
skewness: 0.276029
Alpha:
min: 0 (0)
max: 65535 (1)
mean: 37631.4 (0.574219)
standard deviation: 32404.5 (0.494461)
kurtosis: -1.90988
skewness: 0.300201
Alpha: none #0000000000000000
Histogram:
436: ( 0, 0, 0, 0) #0000000000000000 none
146: ( 0, 0, 0,65535) #000000000000 black
442: (65535,65535,65535,65535) #FFFFFFFFFFFF white
Rendering intent: Undefined
Interlace: None
Background color: white
Border color: rgba(223,223,223,1)
Matte color: grey74
Transparent color: none
Compose: Over
Page geometry: 32x32+0+0
Dispose: Undefined
Iterations: 0
Compression: Undefined
Orientation: Undefined
Properties:
date:create: 2011-03-24T01:57:10+01:00
date:modify: 2010-09-14T09:29:22+02:00
signature: 8e72da04d8726e69b68f4fe89cc4d455d2d4556b42eb24ebb2ad75cb8486731e
Artifacts:
verbose: true
Tainted: False
Filesize: 1.25KBB
Number pixels: 1.02KB
Pixels per second: 10.24TB
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 6.6.8-5 2011-03-17 Q16 http://www.imagemagick.org
Re: Imagemagick and converting to monochrome bitmaps
With your help to pointing me to the right direction and a bit of doc browsing, I found the solution:
This does the job.
Thank you for the help fmw42.
Code: Select all
convert folder1.xpm -background white -alpha Background folder1.xbm
Thank you for the help fmw42.
Re: Imagemagick and converting to monochrome bitmaps
And this does the job for creating masks:
Code: Select all
convert -alpha extract -negate image.xpm image_mask.xbm
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Imagemagick and converting to monochrome bitmaps
Although it won't matter now, but later release it might; the correct syntax in this case isconvert -alpha extract -negate image.xpm image_mask.xbm
convert image options output
see http://www.imagemagick.org/Usage/basics/#cmdline
convert image.xpm -alpha extract -negate image_mask.xbm
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Imagemagick and converting to monochrome bitmaps
that is NOT the right solution. That only sets the color of fully-transparent pixels (it does not make them visible either). Its purpose is to make PNG image compress better by removing the colors from the fuly-transparent pixels.bpopovic wrote:With your help to pointing me to the right direction and a bit of doc browsing, I found the solution:Code: Select all
convert folder1.xpm -background white -alpha Background folder1.xbm
The solution to removing transparency is... IM Examples, masking, Removing transparency.
http://www.imagemagick.org/Usage/masking/#remove
XBM does not support transparency, just pure black and white pixels.
XPM does suport boolean transparency like GIF. But generally has less colors than GIF.
all three XBM, XPM, and GIF are designed for small low color images, icons, and symbols.
they are not designed for general images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Imagemagick and converting to monochrome bitmaps
Thank you for your input. I will look at it if the need arises again.anthony wrote:that is NOT the right solution. That only sets the color of fully-transparent pixels (it does not make them visible either). Its purpose is to make PNG image compress better by removing the colors from the fuly-transparent pixels.bpopovic wrote:With your help to pointing me to the right direction and a bit of doc browsing, I found the solution:Code: Select all
convert folder1.xpm -background white -alpha Background folder1.xbm
The solution to removing transparency is... IM Examples, masking, Removing transparency.
http://www.imagemagick.org/Usage/masking/#remove
I am well aware of that. The images were to be used for a specific purpose as the black & white xbm icons.anthony wrote:XBM does not support transparency, just pure black and white pixels.
XPM does suport boolean transparency like GIF. But generally has less colors than GIF.
all three XBM, XPM, and GIF are designed for small low color images, icons, and symbols.
they are not designed for general images.