Andre Majorel on  wrote...
| On 2007-12-28 00:11 +1000, Anthony Thyssen wrote:
| > Andre Majorel on  wrote...
| > > On 2007-12-24 13:01 +1000, Anthony Thyssen wrote:
| > > > Andre Majorel on  wrote...
| > > >
| > > > > Thanks but that doesn't work too well. The original image is
| > > > > noisy and it's not obvious how to choose shades that are distant
| > > > > enough to avoid the dithering but not so distant that pixels end
| > > > > up remapped to the wrong hue.
| > > > >
| > > > > And the scaling problem is still there.
| > > >
| > > > You can just turn off dithering  using  +dither.
| > > > In that case -map will just set colors to the closest color found
| > > > in the given color map image.
| > >
| > > This *is* with +dither. It's not FS dithering, it's dithering
| > > resulting from noise in the output image.
| > >
| > Oh I see.  That could be a problem.
| >
| > Can you crop a small area from the image, containing the various parts
| > and send me link.
|
| This is it :
|
|   http://www.teaser.fr/~amajorel/misc/sample.ppm.bz2
|
Hmmm.. inital trial...
   convert sample.ppm -blur 0x2 +dither -colors 3 x:

The blur is to try to remove the existing 'dither' pattern that is in
the image.  You could follow that by a sharpen to improve the quality
again afterward.

However the result did not work very well, as -colors quantization is
designed for reducing colors for dithering purposes, and retain as much
fine detail as posible. That is not what you want.


Color segmenting, tries to group colors by size of areas in image, and
not in terms of color dithering.  Note that is ths slower but does seem
to work well.

   convert sample.ppm -blur 0x2 -segment 100 x:

The 100 is the minimum number of pixels that should exist in each
color 'segment' of the color space.

In actual fast that is what you are trying to do... Color Segmenting,
seperating the images into a minimal numebr of distict colors.


So lets try some direct segmentation of the colorspace...


One method is fuzzy matching the image to the three colors wanted.  Say
Black, White and a Orange (color from segmentation routine above) This
basically quantizes the images under your control.

The first color (-fill) is the resulting color, while the fuzz and the second
color (-opaque) specifies a sphere in RGB space of colors that you want
to convert.

    convert sample.ppm -blur 0x2 \
            -fill white -fuzz 20% -opaque white \
            -fill black -fuzz 20% -opaque black \
            -fill '#FEB07C' -fuzz 20% -opaque '#FEB07C' \
            sample_fuzzy_matched.gif

The problem with this is that it tricky to get all 3 fuzz factors
(shpere sizes) just right, and the three overlapping spheres may not
cover the whole RGB color space.  That can be a real problem.



A more automated way, that seperates the whole RGB colorspace into 3
parts, is to handle the black/white parts is to first use an appropriate
automatic black/white threshold technique.  Hopefully this also removes
the orange areas, making them equivelent to the background.

   convert sample.ppm -blur 0x2 +dither -colorspace gray \
           -colors 2 -normalize  sample_bw.gif

That worked well, just the text was extracted.

Now extract just the orange areas, as a mask.
   convert sample.ppm -blur 0x2 \
           -matte -fuzz 20% -transparent '#FEB07C' \
           -channel A -negate +channel \
           -fill '#FEB07C' -colorize 100% \
           sample_orange.gif

To understand try each line in tern to see the effect it has on the
resulting image.

At this point you can 'fill in holes' in the mask using a script by Fred
Weinhaus, or just overlay the two images, or merge them in other ways.

   convert sample_bw.gif sample_orange.gif -composite sample_cleaned.gif



All the above was done in RGB colorspace. The colors may be more easilly
seperated in another color space like HSL (seperating them basied on HUE
and BRIGTHNESS) then convert back to RGB for the final save.



| For reference, this is the sort of transformation I'm after :
|
|   http://www.teaser.fr/~amajorel/misc/quantise-in.png
|   http://www.teaser.fr/~amajorel/misc/quantise-out.png
|
| Yes, the original post mentioned shades of grey and this is just
| black and white (and blue). But you get the general idea which is
| to turn everything into flat tints. It was done using a
| hand-coded program whose gist is :
|
|   if (r < 128 && g < 128 && b < 128) {
|     r =3D 0; g =3D 0; b =3D 0;
|   }
|   else if ((float) b / r >=3D 1.5 && (float) b / g >=3D 1.1) {
|     r =3D 32; g =3D 104; b =3D 192;
|   }
|   else {
|     r =3D 255; g =3D 255; b =3D 255;
|   }
|
For flat tints, convert the image into HSL or HSB color space, then just
threshold Satuation, and brithness appropritally.  After that
you can convert back.

   convert quantise-in.png -colorspace HSB \
           -channel G -threshold 50%
           -channel B -threshold 50% \
           +channel -colorspace RGB   quantize_result.png

Remember when the image is converted to HSB colorspace, the red (R)
channel is hue, the green (G) channel is saturation, and the blue (B)
channel is brightness.

As mentioned above HSB space can be a lot easier than RGB space as
colors are seperated into just a single channel.

As such the equivelent for your 'smaple.ppm' image is, with slight
threshold adjustments....

   convert sample.ppm -blur 0x2 -colorspace HSB \
           -channel G -threshold 20% \
           -channel B -threshold 70% \
           +channel -colorspace RGB   sample_HSB_space.gif

Note bad. the 'G' staturation channel controls the color areas
while the 'B' brightness channel controls the black text areas.
A must better and easier color segmentation technique.

Thanks for the pointer...


  Anthony Thyssen ( System Programmer )    <[EMAIL PROTECTED]>
 -----------------------------------------------------------------------------
     Kernal PANIC: Unable to mount /dev/coffee.machine -- Operator Halted.
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to