Gray value for each point plot over image

조회 수: 2 (최근 30일)
Emre Kayahan
Emre Kayahan 2020년 3월 24일
답변: Rik 2020년 3월 24일
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
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).
Emre Kayahan
Emre Kayahan 2020년 3월 24일
Hi, Rik!
Thank you very much for your comment. I do only need the gray value of where the dot itself is lying on.
Could you please explain it that a Matlab newbie like me would understand? This is literally my very first project with matlab :(
Thanks!

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
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);

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by