Display small images on certain x and y (coordinates)

Hello everyone,
I have 3 images that I want to plot each one in a certain x and y (latitude and longitude) coordinates. The latitude and longitude of each one are presented in a table.
In fact, I want to plot them on the existing figure (adding them) by 0.24 inches of height and 0.24 inches of weight for each of these 3 images. Since these images show the location of the 3 climate stations in the study region. Here is my current figure (I insert all of the code):
% read tif file
[A,R] = readgeoraster('DEM_30s.tif', 'OutputType', 'double');
low_single = typecast(uint8([255 255 127 255]), 'single');
mask = low_single==A;
A = A - min(A(~mask), [], 'all');
% creating colormap changing from white to brown as shown in image in the question
brown_color = [0.8 0.2 0.1];
light_brown = [0.95 0.9 0.8];
t = linspace(0, 1, max(A,[],'all'))';
cmap = t.*brown_color + (1-t).*light_brown;
gs = geoshow(A, cmap, R);
gs.CData(repmat(mask,1,1,3)) = 255;
axis equal
box on
xticks(44:1:65);
yticks(24:1:45);
ax = gca
xlim(ax, xlim(ax)+range(xlim(ax))*[-.02, .02]) % add 2% of space to the left and right of the x limit
Here is the results:
It is possible to add images on it using this code:
hold on
[img, ~, tr] = imread('img1.png');
im = image('CData',flipud(img),'XData',[50 51],'YData',[35 36]);
im.AlphaData = tr;
hold off
But the problem is I want to use the coordinate table that I attached, to add on the existing figure (no change XData and YData manually) and have all small images in 0.24 inches height and weight. So if anyone can tell me what I should do I would be so grateful. I have more than 100 images and 100 corresponding coordinates and these 3 just for example that I cliped from original table.
I attached all 3 small images and the coordinate table. Also, tif file uploaded here my google drive.
Thank you so much ?

 Accepted Answer

Adam Danz
Adam Danz on 13 Apr 2020
Edited: Adam Danz on 13 Apr 2020
Check out the documentation for image(x,y,C)
In short, you need to calculate the [x1,x2], [y1,y2] coordinates where (x1,y1) is the lower left corner and (x2,y2) is the upper right corner.
The coordinates will be in data units so you won't be able to specify the size in inches. Once you decide which size is best, compute the corner coordinates you just need to use the data from your coordinates table which are the centers of the image and +/- 1/2 the width and height. Since you're already using axis equal you don't have to worry about aspect ratio problems.
If you get stuck, share what you've got and we can help get you over the hump.

7 Comments

BN
BN on 13 Apr 2020
Edited: BN on 13 Apr 2020
Dear Adam Danz, According to your answer at the end is the result could be something like this (that I make it in the power point)?
I meant the images are too large to use in the figure so I think it is good to make them small as 0.24 inches.
one more question is when you said you need to calculate the [x1,x2], [y1,y2] coordinates where (x1,y1) is the lower left corner and (x2,y2) is the upper right corner. I just have one lat and one lon for each image! I would be grateful if you can give me a small example of it. Thanks
You can control the size of the image by specifying the coordinates.
For example, let's say the images should be 1x1 [lat x lon] and the center should be at 63.2 and 59.8. The lower left corner will be at
[63.2, 59.8] - [1,1]/2
and the upper right corner will be at
[63.2, 59.8] + [1,1]/2
Well, first I want to thank you, I tried to do it for the first image.
% for first coordinate
LowerLeftCornerLat = 30.37 - (1/2);
LowerLeftCornerLon = 48.21 - (1/2);
UperrRightCornerLat = 30.37 + (1/2);
UperrRightCornerLon = 48.24 + (1/2);
img1_lon = [LowerLeftCornerLon,UperrRightCornerLon];
img1_lat = [LowerLeftCornerLat,UperrRightCornerLat];
c= imread('img1.png');
image (img1_lon,img1_lat,c)
This resulted:
and when I hold on it with my map this happen:
Am I right? unfortunately, my .png was transparent but here the black background appears and its rotated (black pie was down but in the map black pie goes to top. Also, did you know how I can make it smaller?
Thank you
That looks right. Note that when the image() function creates the axes, the y-axis is in reverse direction. That's why the pie chart is flipped between the two axes.
To make it smaller, you just need to specify a smaller size. Your current size is 1 longitude x 1 latitude.
[63.2, 59.8] - [1,1]/2
To make it 2/3 lat x 2/3 lon,
[63.2, 59.8] - [2/3, 2/3]/2
To get rid of the black background, follow Walter's advice in this answer.
I am really thank you, I successfully done it for one point.
I used lat/lon +-((4/10)/2)
And this modification:
hold on
[c, ~, tr] = imread('img1.png');
im = image (img1_lon,img1_lat,flipud(c));
im.AlphaData = tr;
Thank you again
Best Regards

Sign in to comment.

More Answers (0)

Products

Release

R2020a

Asked:

BN
on 13 Apr 2020

Commented:

on 14 Apr 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!