1
$\begingroup$

I want to overlay a set of points onto a distance transform of them. But, I don't really like the black default color of the distance transform. Is there a way to change this?

Given the points pts:

pts = RandomReal[{-1, 1}, {1000, 2}];

We can compute their distance transform image (+ ImageAdjust):

Dpts = DistanceTransform[Graphics[Point[pts]]] // ImageAdjust;

Then, compose this image with the points (say, red points):

ImageCompose[Dpts, Graphics[{RGBColor[0.82, 0., 0.34], Point[pts]}]]

To obtain a nice overlay, but it's not pretty (it's, well, too "dark"):

distance transform

Can we change the color appearance of the distance transform?

Additionally, can we adjust the image resolution? Zooming in just makes evident that the image is not very high-res.

Thanks!

$\endgroup$
0

2 Answers 2

2
$\begingroup$

Generally, I really recommend image processing docs - lots useful stuff there:

DistanceTransform resolution depends on your original image resolution which you can control in Graphics:

dpts = ImageAdjust[DistanceTransform[Graphics[Point[pts], ImageSize -> 500]]]

There are many ways to change color schemes. For instance:

Colorize[dpts, ColorFunction -> "Rainbow"];
ImageCompose[%,Graphics[{RGBColor[0.82,0.,0.34],Point[pts]}]]

enter image description here

Available color schemes are listed here:

http://reference.wolfram.com/language/guide/ColorSchemes.html

Another method would be changing colors based on another image

i = ExampleData[{"TestImage", "Apples"}]

enter image description here

color distribution making use of HistogramTransform:

HistogramTransform[ColorConvert[dpts,"RGB"],i];
ImageCompose[%,Graphics[{RGBColor[0.82,0.,0.34],Point[pts]}]]

enter image description here

$\endgroup$
2
$\begingroup$

As Vitaliy notes, Colorize[] is the key. Here, I'll demonstrate a slightly different way of putting in the markers:

BlockRandom[SeedRandom[42]; (* for reproducibility *)
            pts = RandomReal[{-1, 1}, {1000, 2}];]

npts = Rasterize[Graphics[{PointSize[Small], Point[pts]}], "Image",
                 ImageResolution -> 300];

dpts = Colorize[ImageAdjust[DistanceTransform[npts]], ColorFunction -> "LakeColors"];

npts = Colorize[npts, ColorFunction -> (Blend[{RGBColor[0.82, 0., 0.34, 1],
                                               Transparent}, #] &)];

ImageCompose[dpts, npts]

DistanceTransform + markers

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.