2
$\begingroup$

I have an image img1 and some data with a density plot plot1 to reflect the target position of the image. I tried to combine img1 and plot1 as below:-

targetPosition = BlockRandom[SeedRandom[123]; RandomReal[100, {35, 50}]];
img1 = ImageCrop[ExampleData[{"TestImage", "Airport"}], {1000, 700}];
plot1 = ListDensityPlot[Exp@targetPosition, 
  AspectRatio -> ImageAspectRatio@img1, PlotRange -> All, 
  ImageSize -> ImageDimensions[img1], Axes -> False, Frame -> None];
ImageAdd[ImageMultiply[plot1, 0.6], ImageMultiply[img1, 0.4]]

enter image description here

As you can see, there's still a margin here. Thus the position will have errors due to the margin. How can I get rid of the margin?

Many thanks!

$\endgroup$
  • $\begingroup$ This problem is quite similar to your previous one from a few days ago, which was solved by using GeoRangePadding -> None... $\endgroup$ – MarcoB Jun 20 '18 at 3:28
  • $\begingroup$ Yes. Thus I was thinking the trick should be some Padding options at ImageAdd. I now realized that the Padding option should be set in ListDensityPlot. Many thanks. $\endgroup$ – H42 Jun 20 '18 at 3:37
3
$\begingroup$

PlotRangePadding >> Details

PlotRangePadding -> Automatic adds a total of 4% for PlotRange settings All, Full, and Automatic. For explicit settings, it adds no padding.

Adding PlotRangePadding -> 0 to ListDensityPlot gives

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks. I was stuck in the options of ImageAdd. Now it is solved! $\endgroup$ – H42 Jun 20 '18 at 3:04

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.