Gray value for each point plot over image
2 次查看(过去 30 天)
显示 更早的评论
Hi,
currently I am facing a question and hope that you guys could help me on that one.
I have plotted some datapoints (coordinates) over an image (Citymap of a city in Germany) and I do need to get the gray values for each point. The PNG is already converted to gray. I will attach you some screenshots, so that you are able to understand it. There are 808 points plotted in total. The file which is showing you the plot is called "MapPunkte" and also I am showing you the set of coordinates which are plotted named in the file "Punkte". Below you can see the code I already have written
clc
clear all
% Points to be plotted
load('Referenzpunkte.mat')
fig=figure('rend','painters','pos',[10 10 560*2*1.15 420*2])
img = imread('MapBW.png');
% Converting to gray
colormap(gray(256))
% Boundaries figure
min_x = 6.4037;
max_x = 6.7041;
min_y = 51.2852;
max_y = 51.4048;
imagesc([min_x max_x], [min_y max_y], flipud(img));
hold on
scatter(Punkte(:,1),Punkte(:,2),'filled');
% Set squares for each point
plot(Punkte(:,1),Punkte(:,2),'s','MarkerSize',24,'MarkerEdgeColor','r')
2 个评论
Rik
2020-3-24
Do you need the mean value of everything inside the square? Or just on the dot itself? In the latter case you could round Punkte and use that to index your image (use sub2ind first).
回答(1 个)
Rik
2020-3-24
Since the Punkte array contains coordinates, you can convert them to indices. You need a way to translate the x and y positions to the positions in your image. I will leave that part of the correction for now. Let me know if you need help with that. Once you have converted Punkte to the image coordinates you can use the code below.
ind=sub2ind(size(img),round(Punkte(:,1)),round(Punkte(:,2)));
result=img(ind);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!