Is there an algorithm (in imagemagick) which scales a greyscale image up to a black and white image with the express goal of neither adding nor removing information?
(basically this is what would ideally be done to input images for potrace)
Scale up and reduce to BW algorithm?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Scale up and reduce to BW algorithm?
Interesting question.
If your image has 256 levels of gray (8-bit), and you reduce it to black and white, you need to first enlarge it by 16-times in each direction to contain the same amount of data. (16*16 = 256.)
And the process should be reversible: from the large monochrome image, shrinking it back should restore the original.
For example, g.png is an 8-bit grayscale image, size 267x233 pixels. We make g2.png, with 4272x3728 pixels that are each black or white. Then we reverse the process.
We have restored the original, to about 0.4% RMSE, which is all we can expect for 8-bit images.
EDIT: I should have said, those commands are Windows CMD syntax. Adjust as required for other shells.
EDIT2: I don't know what you mean about potrace. Perhaps I misunderstand what you want.
If your image has 256 levels of gray (8-bit), and you reduce it to black and white, you need to first enlarge it by 16-times in each direction to contain the same amount of data. (16*16 = 256.)
And the process should be reversible: from the large monochrome image, shrinking it back should restore the original.
For example, g.png is an 8-bit grayscale image, size 267x233 pixels. We make g2.png, with 4272x3728 pixels that are each black or white. Then we reverse the process.
Code: Select all
%IM%convert xc:black xc:white +append bw.png
%IM%convert g.png -resize 1600% -remap bw.png g2.png
%IM%convert g2.png -scale "267x233^!" +depth 8 g3.png
%IM%compare -metric RMSE g3.png g.png NULL:
262.524 (0.00400586)
EDIT: I should have said, those commands are Windows CMD syntax. Adjust as required for other shells.
EDIT2: I don't know what you mean about potrace. Perhaps I misunderstand what you want.
snibgo's IM pages: im.snibgo.com