# Overlay two images

I have a series of endoscopic images taken by two cameras at the same time.

A color image:

and a fluorescent image indicating cancerous cells

I now want to overlay the two images to indicate the cancer in the color image.

ImageCompose[img1, {img2, 0.35}]


you can see that it does not match exactly. I need a way to match both images. Another problem is, sometimes the color camera zoomed a little in while the fluorescent image does not.

In the fluorescent image everything but the bright area should be omitted.

The color image is the basis and the fluoro image should be fitted to it, preferably in some false coloring.

Here are two corresponding images: pair 1

im1col=Import["http://i.imgur.com/shzDETI.jpg"]
im1fluo=Import["http://i.imgur.com/Yh9iAXH.jpg"]


pair2

im2col=Import["http://i.imgur.com/ZnUJFrv.jpg"]
im2fluo=Import["http://imgur.com/VHlrpNj.jpg"]

-
@Pickett thanks, corrected. –  spore234 May 29 at 10:23
What is the meaning of the axis ticks marks? If the images can be zoomed independently you'll need some scale hint to match the relative sizes –  belisarius May 29 at 12:13
@belisarius the axis are just arbitrary points and are only there because I converted the images from matlab files. An ideal solution would be an algorithm that could detect wheter the image is zoomed and scale the fluoro image accordingly. –  spore234 May 29 at 13:57
I don't think that is possible. If it were, you should be able to detect the cancerous cells just from the color image –  belisarius May 29 at 14:20

I'm providing what I've done so far. I'm using Binarize to detect the yellow part of the fluorescent image which is not great, but I hope this answer can save someone who knows how to do that in a better way some grunt work.

im1col = Import["http://i.imgur.com/shzDETI.jpg"];
im1fluo = Import["http://i.imgur.com/Yh9iAXH.jpg"];
removeFrame[img_] :=
ColorNegate@ImageCrop@DeleteSmallComponents@ColorNegate@Binarize[img]
highlightCancerousCells[img_, fluo_] := HighlightImage[
ImageCrop@img,
removeFrame[fluo],
{{#, 0}, {#2, 0}} & @@ (ImageDimensions[ImageCrop@img] -
ImageDimensions[removeFrame[fluo]])
]
]
highlightCancerousCells[im1col, im1fluo]


The algorithm can be outlined thus:

1. Take the fluorescent image and crop away everything but the fluorescent part
2. Crop away the whitespace at the top and right side of the color image. This preserves the axes on the bottom left side.
3. Check the difference in image dimensions between the new fluorescent image and the color image. Pad the fluorescent image accordingly on the bottom left side with black color.
4. Use the binarized version of the fluorescent image, in which everything is black except for the yellow parts, to highlight the color image.
-