Page 1 of 1

[Solved] Convert BMP to 8-bit with specific colormap order

Posted: 2013-02-01T01:31:32-07:00
by Sam.
This image is a montage of exactly 256 different colored 10x10 squares tiled to 32x8 and is a 24-bit BMP. I need to convert it to an 8-bit paletted (256 color) BMP, but I need to make sure that the first entry in the colormap corresponds to tile 1x1 (row 1 column 1), the second entry in the color map corresponds to tile 1x2 (row 1 column 2), etc. As there are only 256 colors to begin with, it is very important that the image data not be altered or damaged by the conversion to colormapped 8-bit. I have tried quite a few combinations of parameters, but I haven't been able to get it to come out right. Can someone please help me? Even sending me the end result would be good enough at this point...

Note that I am using the command line version of ImageMagick.

TIA,
Sam.



Here is the identify information for the linked to image:

Code: Select all

Image: Palette.bmp
  Format: BMP (Microsoft Windows bitmap image)
  Class: DirectClass
  Geometry: 320x80+0+0
  Units: PixelsPerCentimeter
  Type: Palette
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 127.5 (0.5)
      standard deviation: 73.9003 (0.289805)
      kurtosis: -1.20004
      skewness: 9.57926e-014
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 127.5 (0.5)
      standard deviation: 73.9003 (0.289805)
      kurtosis: -1.20004
      skewness: 9.57926e-014
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 127.5 (0.5)
      standard deviation: 73.9003 (0.289805)
      kurtosis: -1.20004
      skewness: 9.57926e-014
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 127.5 (0.5)
      standard deviation: 73.9003 (0.289805)
      kurtosis: -1.20004
      skewness: 9.57926e-014
  Colors: 256
  Histogram:
       100: (  0,  0,  0) #000000 black
       100: (  1,  1,  1) #010101 srgb(1,1,1)
       100: (  2,  2,  2) #020202 srgb(2,2,2)
       100: (  3,  3,  3) #030303 grey1
       100: (  4,  4,  4) #040404 srgb(4,4,4)
       100: (  5,  5,  5) #050505 grey2
       100: (  6,  6,  6) #060606 srgb(6,6,6)
       100: (  7,  7,  7) #070707 srgb(7,7,7)
       100: (  8,  8,  8) #080808 grey3
       100: (  9,  9,  9) #090909 srgb(9,9,9)
       100: ( 10, 10, 10) #0A0A0A grey4
       100: ( 11, 11, 11) #0B0B0B srgb(11,11,11)
       100: ( 12, 12, 12) #0C0C0C srgb(12,12,12)
       100: ( 13, 13, 13) #0D0D0D grey5
       100: ( 14, 14, 14) #0E0E0E srgb(14,14,14)
       100: ( 15, 15, 15) #0F0F0F grey6
       100: ( 16, 16, 16) #101010 srgb(16,16,16)
       100: ( 17, 17, 17) #111111 srgb(17,17,17)
       100: ( 18, 18, 18) #121212 grey7
       100: ( 19, 19, 19) #131313 srgb(19,19,19)
       100: ( 20, 20, 20) #141414 grey8
       100: ( 21, 21, 21) #151515 srgb(21,21,21)
       100: ( 22, 22, 22) #161616 srgb(22,22,22)
       100: ( 23, 23, 23) #171717 grey9
       100: ( 24, 24, 24) #181818 srgb(24,24,24)
       100: ( 25, 25, 25) #191919 srgb(25,25,25)
       100: ( 26, 26, 26) #1A1A1A grey10
       100: ( 27, 27, 27) #1B1B1B srgb(27,27,27)
       100: ( 28, 28, 28) #1C1C1C grey11
       100: ( 29, 29, 29) #1D1D1D srgb(29,29,29)
       100: ( 30, 30, 30) #1E1E1E srgb(30,30,30)
       100: ( 31, 31, 31) #1F1F1F grey12
       100: ( 32, 32, 32) #202020 srgb(32,32,32)
       100: ( 33, 33, 33) #212121 grey13
       100: ( 34, 34, 34) #222222 srgb(34,34,34)
       100: ( 35, 35, 35) #232323 srgb(35,35,35)
       100: ( 36, 36, 36) #242424 grey14
       100: ( 37, 37, 37) #252525 srgb(37,37,37)
       100: ( 38, 38, 38) #262626 grey15
       100: ( 39, 39, 39) #272727 srgb(39,39,39)
       100: ( 40, 40, 40) #282828 srgb(40,40,40)
       100: ( 41, 41, 41) #292929 grey16
       100: ( 42, 42, 42) #2A2A2A srgb(42,42,42)
       100: ( 43, 43, 43) #2B2B2B grey17
       100: ( 44, 44, 44) #2C2C2C srgb(44,44,44)
       100: ( 45, 45, 45) #2D2D2D srgb(45,45,45)
       100: ( 46, 46, 46) #2E2E2E grey18
       100: ( 47, 47, 47) #2F2F2F srgb(47,47,47)
       100: ( 48, 48, 48) #303030 grey19
       100: ( 49, 49, 49) #313131 srgb(49,49,49)
       100: ( 50, 50, 50) #323232 srgb(50,50,50)
       100: ( 51, 51, 51) #333333 grey20
       100: ( 52, 52, 52) #343434 srgb(52,52,52)
       100: ( 53, 53, 53) #353535 srgb(53,53,53)
       100: ( 54, 54, 54) #363636 grey21
       100: ( 55, 55, 55) #373737 srgb(55,55,55)
       100: ( 56, 56, 56) #383838 grey22
       100: ( 57, 57, 57) #393939 srgb(57,57,57)
       100: ( 58, 58, 58) #3A3A3A srgb(58,58,58)
       100: ( 59, 59, 59) #3B3B3B grey23
       100: ( 60, 60, 60) #3C3C3C srgb(60,60,60)
       100: ( 61, 61, 61) #3D3D3D grey24
       100: ( 62, 62, 62) #3E3E3E srgb(62,62,62)
       100: ( 63, 63, 63) #3F3F3F srgb(63,63,63)
       100: ( 64, 64, 64) #404040 grey25
       100: ( 65, 65, 65) #414141 srgb(65,65,65)
       100: ( 66, 66, 66) #424242 grey26
       100: ( 67, 67, 67) #434343 srgb(67,67,67)
       100: ( 68, 68, 68) #444444 srgb(68,68,68)
       100: ( 69, 69, 69) #454545 grey27
       100: ( 70, 70, 70) #464646 srgb(70,70,70)
       100: ( 71, 71, 71) #474747 grey28
       100: ( 72, 72, 72) #484848 srgb(72,72,72)
       100: ( 73, 73, 73) #494949 srgb(73,73,73)
       100: ( 74, 74, 74) #4A4A4A grey29
       100: ( 75, 75, 75) #4B4B4B srgb(75,75,75)
       100: ( 76, 76, 76) #4C4C4C srgb(76,76,76)
       100: ( 77, 77, 77) #4D4D4D grey30
       100: ( 78, 78, 78) #4E4E4E srgb(78,78,78)
       100: ( 79, 79, 79) #4F4F4F grey31
       100: ( 80, 80, 80) #505050 srgb(80,80,80)
       100: ( 81, 81, 81) #515151 srgb(81,81,81)
       100: ( 82, 82, 82) #525252 grey32
       100: ( 83, 83, 83) #535353 srgb(83,83,83)
       100: ( 84, 84, 84) #545454 grey33
       100: ( 85, 85, 85) #555555 srgb(85,85,85)
       100: ( 86, 86, 86) #565656 srgb(86,86,86)
       100: ( 87, 87, 87) #575757 grey34
       100: ( 88, 88, 88) #585858 srgb(88,88,88)
       100: ( 89, 89, 89) #595959 grey35
       100: ( 90, 90, 90) #5A5A5A srgb(90,90,90)
       100: ( 91, 91, 91) #5B5B5B srgb(91,91,91)
       100: ( 92, 92, 92) #5C5C5C grey36
       100: ( 93, 93, 93) #5D5D5D srgb(93,93,93)
       100: ( 94, 94, 94) #5E5E5E grey37
       100: ( 95, 95, 95) #5F5F5F srgb(95,95,95)
       100: ( 96, 96, 96) #606060 srgb(96,96,96)
       100: ( 97, 97, 97) #616161 grey38
       100: ( 98, 98, 98) #626262 srgb(98,98,98)
       100: ( 99, 99, 99) #636363 grey39
       100: (100,100,100) #646464 srgb(100,100,100)
       100: (101,101,101) #656565 srgb(101,101,101)
       100: (102,102,102) #666666 grey40
       100: (103,103,103) #676767 srgb(103,103,103)
       100: (104,104,104) #686868 srgb(104,104,104)
       100: (105,105,105) #696969 DimGray
       100: (106,106,106) #6A6A6A srgb(106,106,106)
       100: (107,107,107) #6B6B6B grey42
       100: (108,108,108) #6C6C6C srgb(108,108,108)
       100: (109,109,109) #6D6D6D srgb(109,109,109)
       100: (110,110,110) #6E6E6E grey43
       100: (111,111,111) #6F6F6F srgb(111,111,111)
       100: (112,112,112) #707070 grey44
       100: (113,113,113) #717171 srgb(113,113,113)
       100: (114,114,114) #727272 srgb(114,114,114)
       100: (115,115,115) #737373 grey45
       100: (116,116,116) #747474 srgb(116,116,116)
       100: (117,117,117) #757575 grey46
       100: (118,118,118) #767676 srgb(118,118,118)
       100: (119,119,119) #777777 srgb(119,119,119)
       100: (120,120,120) #787878 grey47
       100: (121,121,121) #797979 srgb(121,121,121)
       100: (122,122,122) #7A7A7A grey48
       100: (123,123,123) #7B7B7B srgb(123,123,123)
       100: (124,124,124) #7C7C7C srgb(124,124,124)
       100: (125,125,125) #7D7D7D grey49
       100: (126,126,126) #7E7E7E gray
       100: (127,127,127) #7F7F7F grey50
       100: (128,128,128) #808080 fractal
       100: (129,129,129) #818181 srgb(129,129,129)
       100: (130,130,130) #828282 grey51
       100: (131,131,131) #838383 srgb(131,131,131)
       100: (132,132,132) #848484 srgb(132,132,132)
       100: (133,133,133) #858585 grey52
       100: (134,134,134) #868686 srgb(134,134,134)
       100: (135,135,135) #878787 grey53
       100: (136,136,136) #888888 srgb(136,136,136)
       100: (137,137,137) #898989 srgb(137,137,137)
       100: (138,138,138) #8A8A8A grey54
       100: (139,139,139) #8B8B8B srgb(139,139,139)
       100: (140,140,140) #8C8C8C grey55
       100: (141,141,141) #8D8D8D srgb(141,141,141)
       100: (142,142,142) #8E8E8E srgb(142,142,142)
       100: (143,143,143) #8F8F8F grey56
       100: (144,144,144) #909090 srgb(144,144,144)
       100: (145,145,145) #919191 grey57
       100: (146,146,146) #929292 srgb(146,146,146)
       100: (147,147,147) #939393 srgb(147,147,147)
       100: (148,148,148) #949494 grey58
       100: (149,149,149) #959595 srgb(149,149,149)
       100: (150,150,150) #969696 grey59
       100: (151,151,151) #979797 srgb(151,151,151)
       100: (152,152,152) #989898 srgb(152,152,152)
       100: (153,153,153) #999999 grey60
       100: (154,154,154) #9A9A9A srgb(154,154,154)
       100: (155,155,155) #9B9B9B srgb(155,155,155)
       100: (156,156,156) #9C9C9C grey61
       100: (157,157,157) #9D9D9D srgb(157,157,157)
       100: (158,158,158) #9E9E9E grey62
       100: (159,159,159) #9F9F9F srgb(159,159,159)
       100: (160,160,160) #A0A0A0 srgb(160,160,160)
       100: (161,161,161) #A1A1A1 grey63
       100: (162,162,162) #A2A2A2 srgb(162,162,162)
       100: (163,163,163) #A3A3A3 grey64
       100: (164,164,164) #A4A4A4 srgb(164,164,164)
       100: (165,165,165) #A5A5A5 srgb(165,165,165)
       100: (166,166,166) #A6A6A6 grey65
       100: (167,167,167) #A7A7A7 srgb(167,167,167)
       100: (168,168,168) #A8A8A8 grey66
       100: (169,169,169) #A9A9A9 DarkGray
       100: (170,170,170) #AAAAAA srgb(170,170,170)
       100: (171,171,171) #ABABAB grey67
       100: (172,172,172) #ACACAC srgb(172,172,172)
       100: (173,173,173) #ADADAD grey68
       100: (174,174,174) #AEAEAE srgb(174,174,174)
       100: (175,175,175) #AFAFAF srgb(175,175,175)
       100: (176,176,176) #B0B0B0 grey69
       100: (177,177,177) #B1B1B1 srgb(177,177,177)
       100: (178,178,178) #B2B2B2 srgb(178,178,178)
       100: (179,179,179) #B3B3B3 grey70
       100: (180,180,180) #B4B4B4 srgb(180,180,180)
       100: (181,181,181) #B5B5B5 grey71
       100: (182,182,182) #B6B6B6 srgb(182,182,182)
       100: (183,183,183) #B7B7B7 srgb(183,183,183)
       100: (184,184,184) #B8B8B8 grey72
       100: (185,185,185) #B9B9B9 srgb(185,185,185)
       100: (186,186,186) #BABABA grey73
       100: (187,187,187) #BBBBBB srgb(187,187,187)
       100: (188,188,188) #BCBCBC srgb(188,188,188)
       100: (189,189,189) #BDBDBD grey74
       100: (190,190,190) #BEBEBE grey
       100: (191,191,191) #BFBFBF grey75
       100: (192,192,192) #C0C0C0 silver
       100: (193,193,193) #C1C1C1 srgb(193,193,193)
       100: (194,194,194) #C2C2C2 grey76
       100: (195,195,195) #C3C3C3 srgb(195,195,195)
       100: (196,196,196) #C4C4C4 grey77
       100: (197,197,197) #C5C5C5 srgb(197,197,197)
       100: (198,198,198) #C6C6C6 srgb(198,198,198)
       100: (199,199,199) #C7C7C7 grey78
       100: (200,200,200) #C8C8C8 srgb(200,200,200)
       100: (201,201,201) #C9C9C9 grey79
       100: (202,202,202) #CACACA srgb(202,202,202)
       100: (203,203,203) #CBCBCB srgb(203,203,203)
       100: (204,204,204) #CCCCCC grey80
       100: (205,205,205) #CDCDCD srgb(205,205,205)
       100: (206,206,206) #CECECE srgb(206,206,206)
       100: (207,207,207) #CFCFCF grey81
       100: (208,208,208) #D0D0D0 srgb(208,208,208)
       100: (209,209,209) #D1D1D1 grey82
       100: (210,210,210) #D2D2D2 srgb(210,210,210)
       100: (211,211,211) #D3D3D3 LightGray
       100: (212,212,212) #D4D4D4 grey83
       100: (213,213,213) #D5D5D5 srgb(213,213,213)
       100: (214,214,214) #D6D6D6 grey84
       100: (215,215,215) #D7D7D7 srgb(215,215,215)
       100: (216,216,216) #D8D8D8 srgb(216,216,216)
       100: (217,217,217) #D9D9D9 grey85
       100: (218,218,218) #DADADA srgb(218,218,218)
       100: (219,219,219) #DBDBDB grey86
       100: (220,220,220) #DCDCDC gainsboro
       100: (221,221,221) #DDDDDD srgb(221,221,221)
       100: (222,222,222) #DEDEDE grey87
       100: (223,223,223) #DFDFDF srgb(223,223,223)
       100: (224,224,224) #E0E0E0 grey88
       100: (225,225,225) #E1E1E1 srgb(225,225,225)
       100: (226,226,226) #E2E2E2 srgb(226,226,226)
       100: (227,227,227) #E3E3E3 grey89
       100: (228,228,228) #E4E4E4 srgb(228,228,228)
       100: (229,229,229) #E5E5E5 grey90
       100: (230,230,230) #E6E6E6 srgb(230,230,230)
       100: (231,231,231) #E7E7E7 srgb(231,231,231)
       100: (232,232,232) #E8E8E8 grey91
       100: (233,233,233) #E9E9E9 srgb(233,233,233)
       100: (234,234,234) #EAEAEA srgb(234,234,234)
       100: (235,235,235) #EBEBEB grey92
       100: (236,236,236) #ECECEC srgb(236,236,236)
       100: (237,237,237) #EDEDED grey93
       100: (238,238,238) #EEEEEE srgb(238,238,238)
       100: (239,239,239) #EFEFEF srgb(239,239,239)
       100: (240,240,240) #F0F0F0 grey94
       100: (241,241,241) #F1F1F1 srgb(241,241,241)
       100: (242,242,242) #F2F2F2 grey95
       100: (243,243,243) #F3F3F3 srgb(243,243,243)
       100: (244,244,244) #F4F4F4 srgb(244,244,244)
       100: (245,245,245) #F5F5F5 grey96
       100: (246,246,246) #F6F6F6 srgb(246,246,246)
       100: (247,247,247) #F7F7F7 grey97
       100: (248,248,248) #F8F8F8 srgb(248,248,248)
       100: (249,249,249) #F9F9F9 srgb(249,249,249)
       100: (250,250,250) #FAFAFA grey98
       100: (251,251,251) #FBFBFB srgb(251,251,251)
       100: (252,252,252) #FCFCFC grey99
       100: (253,253,253) #FDFDFD srgb(253,253,253)
       100: (254,254,254) #FEFEFE srgb(254,254,254)
       100: (255,255,255) #FFFFFF white
  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)
  Interlace: None
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Compose: Over
  Page geometry: 320x80+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: Undefined
  Orientation: Undefined
  Properties:
    date:create: 2013-02-01T01:52:37-06:00
    date:modify: 2013-02-01T01:52:37-06:00
    signature: 88d86936f4e44b6a4ecd9b3d7bf55d83e30bbd9035fc379c0db766a62fe57621
  Artifacts:
    filename: Palette.bmp
    verbose: true
  Tainted: False
  Filesize: 76.9KB
  Number pixels: 25.6K
  Pixels per second: 9.223372EB
  User time: 0.000u
  Elapsed time: 0:01.000
  Version: ImageMagick 6.8.1-10 2013-01-10 Q16 http://www.imagemagick.org

Re: Convert BMP to 8-bit with specific colormap order

Posted: 2013-02-01T02:36:23-07:00
by snibgo
I don't think there is a way to guarantee a particular palette order. However, it seems that this does what you want (in IM v 6.7.9 on Windows7):

Code: Select all

"%IMG%convert" palette.bmp -set colorspace RGB -colorspace Gray -type Palette p.bmp
"identify -verbose" shows the palette in p.bmp, and "compare" verifies the colours in the two files are identical.

Re: Convert BMP to 8-bit with specific colormap order

Posted: 2013-02-01T03:17:14-07:00
by snibgo
Update: we don't need "-colorspace Gray", so the command simplifies to:

Code: Select all

"%IMG%convert" palette.bmp -set colorspace RGB -type Palette p.bmp

Re: Convert BMP to 8-bit with specific colormap order

Posted: 2013-02-01T13:40:58-07:00
by Sam.
snibgo wrote:Update: we don't need "-colorspace Gray", so the command simplifies to:

Code: Select all

"%IMG%convert" palette.bmp -set colorspace RGB -type Palette p.bmp
That was indeed what I was looking for, and the palette was saved in the order I wanted. I needed to use a slightly different BMP format, so I ended up using:

Code: Select all

convert.exe palette.bmp -set colorspace RGB -type Palette -compress none BMP3:p.bmp
which works exactly the way I want it to.

Thanks for your help!

-Sam.