5

I needed to overlay a small histogram onto a large image, specifically in the bottom right hand corner. However, I could not do this in an intuitive and computationally cheap fashion due to inexperience. There are two images, the histogram

imgHist=Histogram[{filtGreenLengths, filtRedLengths}, 20, Background -> White,
  ImageSize -> {200, 100}]

and the main image

image

I first tried to directly perform the overlay, using the code

finalPic = ImageCompose[image, {imgHist,0.5}, Scaled[{0.9, 0.085}]]

but the ImageCompose function freaked out and stretched imgHist to equal the size of image and then moved the enormous expanded imgHist to the bottom right hand corner. I could not find an option to turn off this auto-stretching in the documentation. In the end, I had to do this

imgHist = 
  ImageCrop[
   Histogram[{filtGreenLengths, filtRedLengths}, 20, 
    Background -> White, 
    ImageSize -> {200, 100}], {ImageDimensions[image][[1]], 
    ImageDimensions[image][[2]]}, Padding -> Transparent];

in order to get the result I wanted. This appears to be pretty silly and redundant, so what would be a less hackish way of doing this?

March Ho
  • 649
  • 5
  • 15

3 Answers3

5

Does something like this go in the right direction?

enter image description here

George Wolfe
  • 5,462
  • 21
  • 43
2

You could try using an epilog with inset though I'm not sure how much more efficient that'd be compared to the method you have.

TestData = {10, 14, 8, 6, 4, 3, 2.5, 2, 1.5, 1};
TestDataSmall = {2.5, 1.8, 1.5, 1.3, 1.2, 1.};
plotSmall = Histogram[TestDataSmall, PlotRange -> {0, 6}, ImageSize -> {400, 150}];
Histogram[TestData, PlotRange -> {0, 16}, 
    Epilog -> Inset[plotSmal], 
                    Scaled[{0.75, 0.75}]] ]
Jonie
  • 1,199
  • 6
  • 14
2

You should have typed in documentation center that what you are looking for: "overlay" :) Usualy when I'm looking for anything it gives me something.

Also, I always scan See also links (there is Inset in ImageCompose page)

pic = Image[Import["ExampleData/lena.tif"], ImageSize -> 400]
hist = ImageHistogram[pic, ImageSize -> {150, 50}, Background -> Black]

Overlay[{
         pic,
         hist
        }, All, 2, Alignment -> {1, -1}]

enter image description here

Kuba
  • 136,707
  • 13
  • 279
  • 740