Dear stackoverflow community,

I guess I have a relatively easy problem but nonetheless, I have no idea how to solve it.

So I have this figure which is a map of a town I live in. Since Matlab can't possibly know that it is a map, the heigth and length are measured in pixels (I suppose). However, I would love to find or to define realisitic values in that way that it is measured in meters/kilometers, since I'm coding a car sharing simulator and its not that elegant that they lose a certain amount of charge per pixel. Therefore, I'd love to define beforehand that we're dealing with meters instead of pixels without changing the actual size of the figure. So let's imagine that the picture has a resolution of 1024x768 and I want Matlab to interpret this "solution" as 5 km width and 3 km height.

Right now, I simply use imread:

hf = figure();
[B, map] = imread('Hannoverosm.png');
C = imresize(B, 0.975);
imshow(C, map)
有帮助吗?

解决方案

Can't you just create functions to covert from your pixel space to your km space?

function km = pixels2km(pixels)
    km = pixels*(5/1024);
end

function pixels = km2pixels(km)
    pixels = km*(1024/5);
end

Actually these calculations are so simple you probably don't even need the functions. Also since pixel space is discrete you need to decide on the best method for rounding (probably floor or ceil depending on which corner you're making the 'origin'

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top