Page 1 of 1

Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T18:11:28-07:00
by bpopovic
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
Image

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

Image 3: Example how IM handles the same conversion:
Image

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.

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T18:45:07-07:00
by fmw42
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.

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T19:06:48-07:00
by bpopovic
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.
fmw42 wrote:So was that supposed to be png or jpeg?
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: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.
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:

Code: Select all

convert  image.xpm image.xbm
or in the first case

Code: Select all

convert image.png image.xbm

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T19:43:04-07:00
by fmw42
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.

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T19:57:18-07:00
by bpopovic
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

Posted: 2011-03-23T20:06:27-07:00
by bpopovic
Maybie it would help to post the output of identify on folder1.xpm

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
Strangely, IM doesn't recognize transparent color though. :?

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T20:17:25-07:00
by bpopovic
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
This does the job.

Thank you for the help fmw42. :wink:

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T21:17:16-07:00
by bpopovic
And this does the job for creating masks:

Code: Select all

convert -alpha extract -negate image.xpm image_mask.xbm

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-23T21:20:59-07:00
by fmw42
convert -alpha extract -negate image.xpm image_mask.xbm
Although it won't matter now, but later release it might; the correct syntax in this case is

convert image options output

see http://www.imagemagick.org/Usage/basics/#cmdline

convert image.xpm -alpha extract -negate image_mask.xbm

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-03-24T22:41:39-07:00
by anthony
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
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.

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.

Re: Imagemagick and converting to monochrome bitmaps

Posted: 2011-05-25T16:16:05-07:00
by bpopovic
anthony wrote:
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
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.

The solution to removing transparency is... IM Examples, masking, Removing transparency.
http://www.imagemagick.org/Usage/masking/#remove
Thank you for your input. I will look at it if the need arises again.
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.
I am well aware of that. The images were to be used for a specific purpose as the black & white xbm icons.