Page 1 of 1

Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-18T04:06:17-07:00
by kowapuk
Good time,
I work with E-inc displays and I need to load BMP images with 4-bit depth. Images saved using MS Paint in the BMP with 16 colours are displayed correctly.
Converting with ImageMagick does not match with Paint and is displayed on the screen is very faded. I'm trying to make the conversion as same as possible to MS Paint version.

For example, I tried the following commands:
convert input -type Palette + dither -colors 16 -depth 4 BMP3:output.bmp
convert input -type Grayscale -white-threshold 3000% +dither -colors 16 -depth 4 BMP3: output.bmp

Paint, before converting, does some kind of conversion over pixels - it's unclear what.

https://ibb.co/2ZpcMFs - via Paint
https://ibb.co/5hvWL4b - via ImageMagick

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-18T04:20:43-07:00
by snibgo
What version of IM? On what platform?

Please link to your input image.

Remove the space after "+" in "+ dither".

I'm not sure what result you want, but this gives an image with no more than 16 colours, using a palette with 4-bit index. However, each palette entry has 8 bits per channel per pixel.

Code: Select all

convert toes.png -colors 16 BMP3:toes-16-b.bmp
Image

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-18T07:12:41-07:00
by kowapuk
I use ImageMagick-7.0.8-34-Q16-x64-dll.exe on Windows 10

Let me try to explain on another example.

Link on origin image - https://ibb.co/TkHLTyN (resolution is 240x400 px)

When I save the original image in MS Paint to 16-colour BMP, I get a file with size 48 118 bytes (header - 118 bytes)
- link on part of hex: https://ibb.co/Bn1sb2

Then, I try to convert the original image:

Code: Select all

convert text_origin.png +dither -colors 16 BMP3:text_magic.bmp 
And get a file with size 288 054 bytes (24-bits depth):
- link on part of hex: https://ibb.co/JjWBgZr

Then, I try next command:

Code: Select all

convert text_origin.png -type Grayscale -white-threshold 3000% +dither -colors 16 -depth 4 BMP3:240x400.bmp 
Get a file with normal size - 48 118 bytes. Hex - https://ibb.co/GWJhRrw

The difference between the MS Paint and last image command:it's 0xff for first and 0x77 for the second. For this reason, when displaying the second image on the e-ink display, I get a gray picture, instead of a black and white. How to convert an image through ImageMagick to get an image, as if I had converted through Paint?

Note: direct link on original file - https://drive.google.com/open?id=1I5Xft ... Bu5yEBMb6J

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-18T07:48:49-07:00
by snibgo
https://imgbb.com/Bn1sb2 gives "That page doesn't exist", so I can't examine your output from MS Paint.

For v7, I suggest you use "magick", not "convert".

Code: Select all

magick text-origin.png +dither -colors 16 -type palette BMP3:t.bmp
This gives a file of 48118 bytes, with 16 colours in a palette. Is that what you want?

"-white-threshold 3000%" . See http://www.imagemagick.org/script/comma ... -threshold . Your input has no pixels above 3000%, so this option should do nothing. What do you want it to do?
kowapuk wrote:The difference between the MS Paint and last image command:it's 0xff for first and 0x77 for the second.
I don't understand. First what? Second what? What is 0xff?

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-18T08:34:36-07:00
by kowapuk
snibgo wrote: 2019-03-18T07:48:49-07:00 For v7, I suggest you use "magick", not "convert".

Code: Select all

magick text-origin.png +dither -colors 16 -type palette BMP3:t.bmp
This gives a file of 48118 bytes, with 16 colours in a palette. Is that what you want?
I'll check it tomorrow. I look in hex file - seems right.
snibgo wrote: 2019-03-18T07:48:49-07:00 I don't understand. First what? Second what? What is 0xff?
Sorry for my English
Looks on my drive - https://drive.google.com/open?id=1dzqA3 ... ttJJPzXsRI
text_paint.bmp - i have converted it via Paint. In text_paintbmp_hex.PNG shows the hex code of the image.
Same actions I did via ImageMagick: text_convert.bmp and text_convert_bmp_hex.PNG (hex).

And text_magick_bmp_hex.PNG - it's hex file after

Code: Select all

magick text-origin.png +dither -colors 16 -type palette BMP3:t.bmp
. I think it will work.

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-20T02:35:03-07:00
by kowapuk
snibgo wrote: 2019-03-18T07:48:49-07:00

Code: Select all

magick text-origin.png +dither -colors 16 -type palette BMP3:t.bmp
This gives a file of 48118 bytes, with 16 colours in a palette. Is that what you want?
I can't convert as needed.

I have two files in jpg: One and Two.

I want to convert them with the same quality and get the following results (see hex, color depth 4 bits, BMP): One_t and Two_t

Re: Converting any image to 16 colour BMP (4 bits depth) as in MS Paint

Posted: 2019-03-20T07:23:28-07:00
by snibgo
If One_t.bmp contains certain colours. If you want to reduce One.jpg to exactly those colours, and no more, then use "-remap" like this:

Code: Select all

magick One.jpg +dither -remap One_t.bmp out.png
Those colours are a poor selection to represent the image. IM options "-colors" and "posterize" will not select those colours.