2
$\begingroup$

I am trying to compare black&white scans (for starters, only 3 of them) of identical size. I want to highlight the similarities and differences by displaying the first one in red, the second one in blue, the third one in green. When black pixels overlap, the color change should reflect if the pixel is common among 1-2, 1-3, 2-3 or 1-2-3.

My first try is this:

bw1 = Binarize@Graphics[{Disk[]}, PlotRange -> {{-3, 1}, {-2, 2}}];
bw2 = Binarize@Graphics[{Disk[]}, PlotRange -> {{-2, 2}, {-2, 2}}];
bw3 = Binarize@Graphics[{Disk[]}, PlotRange -> {{-2.5, 1.5}, {-3, 1}}];
ColorCombine[{bw1, bw2, bw3}, "RGB"]

graphic output of first command

It's the idea, but I don't like the colors: I would like the original circles to be red-blue-green and the overlaps to be yellow, magenta, cyan for partial overlaps or black for full overlap. So I tried this instead:

ColorCombine[1 - {bw1, bw2, bw3}, "RGB"]

graphic output of first command

Now I am happy with the colors, but I have a problem with the background (exterior of all circles) and the central overlap (intersection of the 3 circles): I would like the intersection to be black and the background to remain white.

I am stuck there.

My secondary question is to scale the problem up. Is there an elegant way to do the same thing with N black&white images instead of 3 ? one would specify that the black parts of image number j should be mapped to some color c[j], the background should stay white, all overlaps should be some interpolation between the corresponding colors and black would only denote a full overlap (black pixel among all N images).

All suggestions for that problem are welcome too.

PS. It is my first project with image processing... but you probably had guessed ;-)

$\endgroup$
  • $\begingroup$ Have you seen this? $\endgroup$ – J. M. is away May 19 '17 at 19:55
  • 1
    $\begingroup$ You can just do ColorReplace[..., {White -> Black, Black -> White}]. The result looks really weird to me, but it's what you asked for. // By the way your ColorCombine[1 - {bw1, bw2, bw3}, "RGB"] gives me an error but ColorNegate@ColorCombine[{bw1, bw2, bw3}, "RGB"] works. $\endgroup$ – Rahul May 19 '17 at 20:03
1
$\begingroup$

Thanks to Rahul, this code works for the comparison between 3 scans:

ColorReplace[ColorNegate@ColorCombine[{bw1, bw2, bw3}, "RGB"],
    {White -> Black, Black -> White}]

For my "real" problem, it gives something like this: real life example

The question for N>=4 inputs is still open.

$\endgroup$
  • 1
    $\begingroup$ Could you explain what you want the colors to do for the N>=4 cases. RGB clearly no longer works. $\endgroup$ – Ian Miller May 20 '17 at 2:46
  • $\begingroup$ @IanMiller For N>=4, I would like to chose N starting colors for each layer and then have each kind of overlap be colored with a new one. As you point out, you can assume that I have defined my own overlap function Overlap[{RGBColor1,RGBColor2,...,RGBColorK}] --> RGBColorOfOverlap for any K\in[2,N] because there is no canonical choice for the overlap anymore. $\endgroup$ – Francois Vigneron May 21 '17 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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