Gray value for each point plot over image
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Rik
le 24 Mar 2020
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).
Réponses (1)
Rik
le 24 Mar 2020
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 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Properties dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!