필터 지우기
필터 지우기

Read coordinates on a txt file and plot them over an image.

조회 수: 3 (최근 30일)
Gabriel
Gabriel 2017년 1월 4일
댓글: Stelios Fanourakis 2018년 5월 1일
Dear all,
I made a program that reads some coordinates (x, y) of a text file and plot the points over a gray image. The problem is that the 'y' coordinates are inverted. This problem doesn't happen when I draw a regular plot (without reading from a file).
How can I fix this issue?
Thanks in advance,
  댓글 수: 3
Gabriel
Gabriel 2017년 1월 4일
It is quite simple, indeed:
[x, y] = textread('coordfile.txt', '%f , %f');
imshow(img, []), hold on;
plot(x, y, 'r*')
I tried to use "flipud" but it didn't solve the problem.
Image Analyst
Image Analyst 2017년 1월 4일
Gabriel, do you want your x axis to be at the top of your image, with rising y values going downward? Or do you want your x axis to be at the bottom of your image, with rising y values going upward? And do you like the way your image is displayed, or do you wish the top were at the bottom and vice versa?

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

답변 (1개)

Stephen23
Stephen23 2017년 1월 4일
편집: Stephen23 2017년 1월 4일
Images are referenced to the top left of the image (due to traditions related to the scanning of a CRT), so this is how all image handling programs work with them. MATLAB simply follows this standard.
People who are used to plotting data relative to an x-axis at the bottom of their plot might get a bit confused, but need to learn that images use a different standard.
A simple internet search shows many questions already dealing with this topic, e.g.:
and is also explained in the documentation for the relevant functions, e.g. imagesc:
"The high-level version of imagesc calls newplot before plotting and sets these axes properties: ... YDir to 'reverse'. Values along the y-axis increase from top to bottom."
  댓글 수: 4
Guillaume
Guillaume 2017년 1월 4일
plot(x, size(img, 1) - y, 'r*')
would solve the problem quickly
Stelios Fanourakis
Stelios Fanourakis 2018년 5월 1일
Hey I am doing something similar but I cannot take anything as a result. I use
filePatternu = fullfile(destinationFolder, '*.dcm'); allFiles = dir(filePatternu);
for k= 2: 1: length(allFiles) baseFileName = allFiles(k).name; % e.g. "1.png" fullFileName = fullfile(destinationFolder, baseFileName); I = dicomread(fullFileName); % img respresents input image. pause(2) [x, y] = textread('imgpositions.txt', '%f , %f'); figure imshow(I, [x y]) drawnow; end
Although, I get no error still I get no image

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

카테고리

Help CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by