Handling text files and viewing annotations on a Picture.

2 views (last 30 days)
I have to import a text file in Matlab that contains several random numbers representing X and Y co-ordinates. Then I have to show these points on a .png picture. The text file contains 20 such points. I used "dlmread" but it makes a single matrix of all these points while I need 20 such matrices. How can I make several Matrices using that text file and how can I show these points in the Picture.?
P.S The points are like:
1428 742
256 84
986 547... etc
These points represent the pixels of a picture and I have to show them in a different color, its like darts hitting the picture but I have no idea how to do it.

Accepted Answer

Image Analyst
Image Analyst on 15 Jan 2015
I fail to see why you need 20 matrices when all your x,y data is in the one matrix you get from dlmread(). How about just calling dlmread() and plot(), something like this:
data = dlmread(filename, ' ');
[rows, columns] = size(data);
imshow(yourImage);
hold on;
for row = 1 : rows
randomColor = rand(1,3);
plot(data(row, 1), data(row, 2), '.', ...
'Color', randomColor, 'MarkerSize', 3);
end
  20 Comments
Image Analyst
Image Analyst on 30 Jan 2015
I'm sure you must have thought of the obvious idea to adjust xRect and yRect so that the rectangle is one pixel smaller:
xRect(row, 1:5) = [x1+1,x2-1,x2-1,x1+1,x1+1];
yRect(row, 1:5) = [y1+1,y1+1,y2-1,y2-1,y1+1];
Was there some reason why it didn't work?
Saad Saboor
Saad Saboor on 2 Feb 2015
No, the code's perfect, I just had to plot the points on the rectangle boundary as blue, so thanks, it's working all fine.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!