jpg to bmp grayscale - colorspace still sRGB

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: jpg to bmp grayscale - colorspace still sRGB

Post by fmw42 »

snibgo wrote:That gives 3 channels/pixel, 8 bits/channel.
I guess that proves that bmp does not support true grayscale or bilevel. The best one can do is palette with two colors, black and white. (or IM is not fully supporting them, if bmp allows them, which I think you said before that it did not.)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpg to bmp grayscale - colorspace still sRGB

Post by snibgo »

As far as I know, BMP supports only 4-channel images: R, G, B and something that is only loosely defined.

It is a very simple (and very old) format that many people (including me) tinkered with. Back in those days, finding two software packages that could interchange image files was somewhat random. And memory (RAM and disk) was expensive, so spreading a gray value across another two redundant channels was extravagant.

I wouldn't be surprised to come across old software that expected non-standard BMP data. The best solution would be to trash that old software. But I suppose a custom IM coder could be written.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: jpg to bmp grayscale - colorspace still sRGB

Post by fmw42 »

IM supports two older formats BMP3 and BMP2, besides the more current BMP (BMP4). But I do not know much about any bmp format other than in the link below. The upcoming IM 6 beta will be able to distinguish them in the verbose info or in the string format "%m".

see
http://www.imagemagick.org/Usage/formats/#bmp
mpheyse
Posts: 3
Joined: 2017-03-03T19:16:25-07:00
Authentication code: 1151

Re: jpg to bmp grayscale - colorspace still sRGB

Post by mpheyse »

I am fairly sure your all wrong and that gray scale BMP's were supported back in the 'old' days. I seem to recall MSpaint locking out the color palette in that grayscale mode, giving a set of common gray values.

As a quick test I opened a RGB channel-copy gray-scale BMP that IM is making, in Photoshop. It did show Three identical channels, and the file is 5MB, I then in Photoshop changed the image to gray-scale and saved it as another BMP. The New image is still gray-scale, is now only 1.32MB and only has 1 channel "Index" (in Photoshop), opening this gray-scale BMP in the MS tools works just fine, and the MS tools save it as new image, which is still a single channel when view in Photoshop (Channel "index")

I found this thread because I also want a gray-scale BMP out of IM.

I guess I should spinup a VM and see if my memory serves me correctly
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: jpg to bmp grayscale - colorspace still sRGB

Post by fmw42 »

You can reduce the size of the grayscale bmp if you tell it you want it to be -type palette (indexed).

Non-indexed:

Code: Select all

convert logo: -colorspace gray logo4.bmp
convert logo: -colorspace gray BMP3:logo3.bmp
convert logo: -colorspace gray BMP2:logo2.bmp
identify logo4.bmp logo3.bmp logo2.bmp
logo4.bmp BMP 640x480 640x480+0+0 8-bit sRGB 922KB 0.010u 0:00.000
logo3.bmp BMP3 640x480 640x480+0+0 8-bit sRGB 922KB 0.010u 0:00.009
logo2.bmp BMP2 640x480 640x480+0+0 8-bit sRGB 922KB 0.000u 0:00.000
Indexed:

Code: Select all

convert logo: -colorspace gray -type palette logo4b.bmp
convert logo: -colorspace gray -type palette BMP3:logo3b.bmp
convert logo: -colorspace gray -type palette BMP2:logo2b.bmp
identify logo4b.bmp logo3b.bmp logo2b.bmp
logo4b.bmp BMP 640x480 640x480+0+0 8-bit sRGB 256c 52.1KB 0.000u 0:00.000
logo3b.bmp BMP3 640x480 640x480+0+0 8-bit sRGB 256c 52KB 0.010u 0:00.000
logo2b.bmp BMP2 640x480 640x480+0+0 8-bit sRGB 256c 308KB 0.010u 0:00.000
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpg to bmp grayscale - colorspace still sRGB

Post by snibgo »

Microsoft Paint v6.3 on Windows 8.1 under "properties" doesn't offer a grayscale option, just "color" or "black and white" which is just those two colours.
mpheyse wrote:... 1 channel "Index" (in Photoshop),
Yes, that's what I called "palette" above.
See https://en.wikipedia.org/wiki/BMP_file_ ... xel_format . That page has expanded since I cited it above, but it still doesn't include a grayscale non-palette format.

Do you really want a grayscale non-palette format? Why?
snibgo's IM pages: im.snibgo.com
mpheyse
Posts: 3
Joined: 2017-03-03T19:16:25-07:00
Authentication code: 1151

Re: jpg to bmp grayscale - colorspace still sRGB

Post by mpheyse »

>o you really want a grayscale non-palette format? Why?
To Pipe, a non-compressed easy pixel format into other programs without duplicating every pixel's value 3or4 times (RGB or RGBA).

BMP is the easiest simplest, and has 0 compression, its a header, and a list of pixels.


Another odd thing I've found is a BMP 24bitcolor, that only contains gray [0x5C] (MSpaint), "identify.exe -verbose" only claims it has one 8-bit channel "gray"

Image: 92-all.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 3x3+0+0
Units: PixelsPerCentimeter
Type: Grayscale
Base type: TrueColor
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
Gray: 8-bit
Channel statistics:
Pixels: 9
Gray:
min: 92 (0.360784)
max: 92 (0.360784)
mean: 92 (0.360784)
standard deviation: 0 (0)
kurtosis: -3
skewness: 0
entropy: -1.#IND
Colors: 1
Histogram:
9: ( 92, 92, 92) #5C5C5C grey36
Rendering intent: Perceptual
Chromaticity:
red primary: (0.64,0.33)
green primary: (0.3,0.6)
blue primary: (0.15,0.06)
white point: (0.3127,0.329)
Matte color: grey74
Background color: white
Border color: srgb(223,223,223)
Transparent color: none
Interlace: None
Intensity: Undefined
Compose: Over
Page geometry: 3x3+0+0
Dispose: Undefined
Iterations: 0
Compression: None
Orientation: Undefined
Properties:
date:create: 2017-03-04T11:36:14-05:00
date:modify: 2017-03-04T11:48:44-05:00
signature: b1487331f52f09b07554b78692408c9617754d8b71c61ca06d4c033c4f859aeb
Artifacts:
verbose: true
Tainted: False
Filesize: 174B
Number pixels: 9
User time: 0.000u
Elapsed time: 0:01.000
Version: ImageMagick 7.0.5-0 Q16 x86 2017-02-20 http://www.imagemagick.org
mpheyse
Posts: 3
Joined: 2017-03-03T19:16:25-07:00
Authentication code: 1151

Re: jpg to bmp grayscale - colorspace still sRGB

Post by mpheyse »

For clarification, Pipe to non-image utilities that don't understand image formats. Chopping off the BMP header isn't hard.


even weirder "convert.exe 92-all.bmp -print "%[mean]" null.bmp"

Returns a value of "23644"

which is 0x5C5C

Which 'looks' like its Two channel, to me.

I would have expected 0x5C5C5C or "6052956" for Three channel (sRGB)
or 0x5C "92" for one channel (gray scale)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpg to bmp grayscale - colorspace still sRGB

Post by snibgo »

mpheyse wrote:To Pipe, a non-compressed easy pixel format into other programs without duplicating every pixel's value 3or4 times (RGB or RGBA).

BMP is the easiest simplest, and has 0 compression, its a header, and a list of pixels.
But that is what the GRAY: and RGB: formats are for. For example:

Code: Select all

convert rose: -colorspace Gray -depth 8 GRAY:x.bin
The input rose: has 3220 pixels. The output has 3220 bytes.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: jpg to bmp grayscale - colorspace still sRGB

Post by snibgo »

mpheyse wrote:even weirder "convert.exe 92-all.bmp -print "%[mean]" null.bmp"

Returns a value of "23644"

which is 0x5C5C

Which 'looks' like its Two channel, to me.
No. It is a 16-bit value, the average of all the values in 92-all.bmp, rounded to the nearest 16-bit integer.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: jpg to bmp grayscale - colorspace still sRGB

Post by fmw42 »

even weirder "convert.exe 92-all.bmp -print "%[mean]" null.bmp"

Returns a value of "23644"
That is because Q16 IM returns raw values in the range 0 to 65535, not 0 to 255. You can get values only in the Q range or 0 to 1. For the latter use "%[fx:mean]". You can scale the values to the range 0 to 255 by using "%[fx:round(255*mean)]"
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: jpg to bmp grayscale - colorspace still sRGB

Post by fmw42 »

BMP does not support an actual grayscale colorspace, only RGB. See http://mathematica.stackexchange.com/qu ... ale-bitmap

Depending upon the tool used to import the BMP, it may report it as colorspace gray (grayscale), if it detects that the colormap only contains R=G=B values. But the BMP header does not say if it is grayscale or color. It assumes only RGB, but permits the R,B,B values to be identical.
Post Reply