last day (15 days later) » 

1:23 AM
2
A: Convert full color image to three color image for e-ink display

fmw42Just adding a bit to Mark Setchell's answer. For printing you might be better dithering your 3 colors. So here is your image with and without dithering using Imagemagick 7. If using Imagemagick 6, replace magick with convert. Input: Create 3 color palette: magick xc:red xc:white xc:black +a...

 
Great stuff! How would you split it into two images - one for red and one for black? That would be needed for the waveshare, which is part of the original question here. Haven't found an answer yet for that, so I thought this would be a good place to raise that.
 
I do not interpret that from your question Please explain further. If it is split for red, what shows where there is not red? My image has only 3 colors as you requested -- red, black, white.
 
The image as processed here is in shades of red, white and black as expected. Waveshare epaper renders it as two images - one for the black portion and one for the red portion. So one would need to generate two images from this image - one having the red pixels and one having the black pixels. However, it is not clear how exactly to achieve that either using imagemagick, or manipulating it directly using Pillow and Python. When I look at the pixel data for the image, it is still as a variation of RGB - like (173, 133, 134) for example. So I can't blindly get out red pixels or black pixels.
 
If you extract the red pixels for your new image, what happens to the white and black pixels? Do they become just black or just transparent? You cannot have an image with only some pixels.
Can you provide an image example for black and for red of what your Waveshare expects?
 
I noticed something rather strange - I checked the histogram of colors on your image above and it shows only red, black and white. However, when I convert a JPG image I found online (as described above), histogram shows a bunch. Each pixel is not just red, white or black in my case. The image that I tried was this - burst.shopify.com/photos/forces-of-nature?q=nature
 
1:23 AM
Did you output as PNG or JPG?
 
JPG is lossy and changes colors. Also did you dither it or not? If you dither, that will introduce new colors also. You need to avoid dithering and save as PNG or GIF
 
So here's what I wanted to do - take an image - convert into red, black, white with dithering, resize to Waveshare size, and then output two images - one for red pixels and one for black pixels.
Ah. I'll try with converting it to PNG first
Or how about BMP? Waveshare library ultimately expects it in BMP (monochrome BMP- one image representing black pixels and the other image representing red pixels)
And yes, I did dither the JPG, which would have added to the woes
 
You cannot have just red pixels in the result or just black pixels in the result. An image has to have all its pixels filled with something. For the red image, what do you want to fill the non-red pixels from the input?
 
for the red image, the non-red pixels should be just white
similarly for the black - non-black pixels should be just white
 
1:29 AM
So you want a white and black image where white represents red and black elsewhere and white and black image where white represents black and black elsewhere? BMP is fine. I will have to check about dithering.
 
I would want a white and black image where black represents black and white represents everything else.
Similarly, another white and black image where black represents RED and white represents everything else.
 
Are you sure? What about the red image? Should it have black representing red or white representing red?
 
black representing the red
Waveshare pixels can be white, black or red each physically. It firsts flips each pixel to show white, then it flips each pixel as necessary to show black, and then flips remaining pixels as necessary to display red - it takes as input two buffers - one for the pixels to flip black, and the other for the pixels to flip red
 
OK, it looks like the dithering does not change the colors.
 
yeah, I just checked with saving as BMP and it kept the colors. Saving as JPG resulted in many different shades.
Ok, with the BMP, I was able to use imagemagick fill and opaque options to get the results I expected:
convert -fill white -opaque black new.bmp new_red.bmp
convert -fill white -opaque red new.bmp new_black.bmp
Does that sound right?
Thanks for the tip about JPG vs PNG/BMP/GIF! It was quite frustrating!!
 
1:46 AM
OK, I have added an Addition to my answer with the code for separating the red and black images. I hope I understand correctly what you want.
 
And then finally to convert the red image to a black image I did the following:
convert -fill black -opaque red new_red.bmp new_red_2.bmp
Yup, that's exactly what I wanted!!
But the command doesn't work with imagemagick 6.8.8, it seems
I'm trying now with 6.9 (still the older version, using convert)
that doesn't work on 6.9 either
I get the following:
convert result.bmp -color-threshold "red-red" -negate red.bmp
convert-im6.q16: unrecognized option `-color-threshold' @ error/convert.c/ConvertImageCommand/1198.
 

last day (15 days later) »