Colors changing when using Inkscape Trace Bitmap

Post questions on how to use or achieve an effect in Inkscape.
ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Tue Oct 11, 2016 9:25 am

Never noticed before until today I was trying to do a simple color test as I wanted to generate some svg's as separate layers.

The bug I'm getting is that the colors I have in my png or bmp do not match after the trace sometimes I get 1 color that matches sometimes not.

Using Inkscape 0.91 on Windows 10

No options are checked I tested a simple 3 color (red,blue,white) design with no overlap and I end up with different color values.

I removed background removed smooth and left stacks on.

I'm up for suggestions on finding a fix for this issue as I am not always using only 3 colors and can be up to 64 diferent color elements and there is no interlace on the images (As I checked the colors in the image with imagemagick and only the colors I wanted showed up in the histogram)

Best Regards

Moini
Posts: 3333
Joined: Mon Oct 05, 2015 10:44 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby Moini » Wed Oct 12, 2016 12:31 am

That usually happens when the number of colors used for the trace in the trace bitmap dialog doesn't match the number of colors in the drawing.

Remember, the pixels on the edges of any plain-colored object are not just either object color or background color, but something in between, to make the edges look less harsh (else you'd get a pixelized appearance with sawtooth distortion).
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby v1nce » Wed Oct 12, 2016 4:22 am

I guess the color reduction is done using median-cut algorithm which is prone to color quantization error.

ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Wed Oct 12, 2016 7:05 am

Thanks to you both at least I know it's not a software bug but more on how it reacts to the image. There wasn't any interlace in the image just plain colors with no mixes on the edges that's why it was bugging me as I know with interlace you can end up with a dozen or more extra mixed colors just for the transition.

ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Mon Nov 07, 2016 10:54 pm

How would one fix this and I'm accepting code level fixes..

Kvec is now free but 127k layers is no way in hell a option for me.

I'll accept a patch or a code fix but even with 256 colors I don't get the same palette. and this is a issue.

I'm working on a multi-image layer convert tool but if the engine scraps the palette (I'm only asking for 256 per image) then it's pointless heck even 2 colors change so this is a problem with conversion ... I'll gladly re-compile if I can get the correct results.

Shawn W. Dion

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby v1nce » Tue Nov 08, 2016 2:48 am

What's you final aim ?
maybe what you want to achieve could be done easily by scripting image magick.

ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Tue Nov 08, 2016 6:16 am

Do a search for kvec vector it's free now however the way it works will make you so many elements for a high definition image that there is no way to work with it.

My reason why I am looking for near perfect colors is for archiving purposes and fundraising as currently our local food bank is out of a roof to help the needy and well I'm trying to generate some funds online to help them out, if by next 2 weeks they don't have another location to distribute the food well some people (at least 70+ families) won't have food on the table x-mas (or for the holidays) I know that some difference won't hurt much but the lady that is in no way technical and that is in charge of the organization would like to keep things as real as possible.

But hey if it's not possible with inkscape I'll do it with kvec with a search and replace tool to split the layers as 90% of the volunteers know how to sow, but using inkscape generates way smaller files.

Shawn W. Dion

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby v1nce » Fri Nov 11, 2016 6:17 am

The following script should work standalone on Linux
You should pass it : path of the bitmap image and output path for the svg

Code: Select all

#!/bin/bash
input=$1
output=$2
histogram="$2.tmp.histo"
tmpsvg="$2.tmp.svg"
tmpmask="$2.tmp.ppm"

convert $input  -format %c -depth 8  histogram:info:"$histogram"
sed -i '$d'  "$histogram"
sort -n -k1,1 -r -o  "$histogram" "$histogram"
echo "<?xml version='1.0' standalone='no'?>" > "$output" ;
echo "<svg version='1.0' xmlns='http://www.w3.org/2000/svg'><g>" >> "$output" ;

i=1;
 while IFS= read -r line; do
  color="${line:27:6}";
  echo "processing color $color $i"
  i=$(($i+1))
  convert "$input" \
  -transparent "#$color" \
  -alpha extract \
  "$tmpmask"
  potrace -s "$tmpmask"   -o  "$tmpsvg"
  sed -ni '/transform/,/g>/p' "$tmpsvg" 
  sed -i "s/#000000/#$color/" "$tmpsvg"
  cat "$tmpsvg" >> "$output"
done < "$histogram"
echo "</g></svg>" >> "$output"
rm "$histogram"
rm "$tmpsvg"
rm "$tmpmask"


for a solution inside inkscape I think you should fill a bug report @ https://bugs.launchpad.net/inkscape

ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Sat Nov 12, 2016 7:38 am

@v1nce

First thanks for taking the time I'm seriously impressed and I'll definitely try it out this week-end. Your code example is so clean I could probably convert a script like this for a DOS batch file using a few tools.

As for the bug report I'm going to investigate the code and see where the color shift might be causing it but I have a feeling that I'll find a type of matrix pattern to calculate the colors.

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby v1nce » Sat Nov 12, 2016 10:51 pm

I'm a bit lazy at rewriting it for dos (plus I don't have a dosbox right now and I never know how much % (%%) you should have) but it should be quite doable.
You'll need
image magick:http://www.imagemagick.org/script/binary-releases.php
potrace:http://potrace.sourceforge.net/#downloading
sed => http://unxutils.sourceforge.net/
I think the following basic commands should be in the textutils or shell utils of http://unxutils.sourceforge.net/ if not you could use the native dos versions
cat => use type
rm => use del
sort => don't know. find ?

maybe if you're on windows 10 it could work right out of the box :http://www.howtogeek.com/249966/how-to-install-and-use-the-linux-bash-shell-on-windows-10/

If you want to patch inkscape then I guess you'll have to look in inkscape/src/trace/quantize.cpp

ShawnWDion
Posts: 70
Joined: Fri Apr 22, 2016 8:32 am

Re: Colors changing when using Inkscape Trace Bitmap

Postby ShawnWDion » Mon Nov 14, 2016 10:00 pm

Hi v1nce,

Thanks for the information was working on making the dos version this week-end, sed was the only one that I was trying to figure out on how to make either via straight dos commands or using a vbs script.

I'll definitely try making it with the information you provided.

ShawnWDion


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: No registered users and 8 guests