Extracting data from a text file.

1 visualización (últimos 30 días)
Saad Saboor
Saad Saboor el 15 de En. de 2015
Respondida: D. Ali el 27 de Abr. de 2019
Please help me with this code. Annotations.text contains the positions for five rectangles. How can I extract the values from text file and use it as position for rectangles.
I=imread('avengers.png');
Data = dlmread('Annotations.txt');
[rows, columns] = size(Data);
imshow(I);
rectangle('Position', 'Curvature',[0,0], 'LineWidth', 2, 'EdgeColor','r');
  2 comentarios
Geoff Hayes
Geoff Hayes el 16 de En. de 2015
Saad - can you provide a sample of the data from the Annotations.text file? We can't offer guidance unless you provide some details concerning the content/format of this file.
Saad Saboor
Saad Saboor el 16 de En. de 2015
Thanks for asking sir, have a look at my code.
Image=imread('avengers.png');
Data1 = dlmread('Annotations.txt');
[rows, columns] = size(Data1);
Data2 = dlmread('randPts1.txt');
[rows1, columns1] = size(Data2);
imshow(Image);
hold on;
xRect(row, 1:5)=0;
yRect(row, 1:5)=0;
for row = 1 : rows;
x1 = Data1(row,1);
y1 = Data1(row,2);
x2 = x1 + Data1(row,3);
y2 = y1 + Data1(row,4);
xRect(row, 1:5) = [x1,x2,x2,x1,x1];
yRect(row, 1:5) = [y1,y1,y2,y2,y1];
rectangle('Position',[Data1(row,1),Data1(row,2),Data1(row,3),...
Data1(row,4)],'Curvature',[0,0],'LineWidth',2, 'EdgeColor','r');
end
for row1 = 1 : rows1;
x = Data2(row1,1);
y = Data2(row1,2);
inside = false;
% See if the x,y is inside any of the rectangles.
for r = 1 : rows
inside = inpolygon(x, y, xRect(r,:),yRect(r,:));
if inside
break;
end
end
if inside
% It's inside one of the rectangles, so plot it in red.
plot(x, y, '.', 'Color', 'green', 'MarkerSize', 15);
else
% It's not inside any rectangle, so plot it in blue.
plot(x, y, '.', 'Color', 'blue', 'MarkerSize', 15);
end
end
Annotations.txt contains the positions for five rectangles:
379 128 131 184
562 142 116 162
778 164 151 154
1058 95 94 100
35 39 208 273
randPts1.txt contains 25 random XY co-ordinates which I have displayed on the picture as Blue points.
My job was to change the color of the points that lie inside a rectangle which I have successfully achieved. Now I have to change the color of the rectangle too but I am not able to write a code for it. This must be the properties of the rectangle:
rectangle('Position',[Data1(row,1),Data1(row,2),Data1(row,3),...
Data1(row,4)],'Curvature',[0,0],'LineWidth',2,...
'Linestyle','--', 'EdgeColor','yellow');
Can you give me a general code for this problem (keeping in mind that I only have to change the properties of the rectangle that contains the plotted points) and also tell me where to place it in my code.?
I also have to calculate the Hit-ratio i.e out of these 25 points, how many of them are hitting the faces and I have to calculate the percentage and display the result as a Bar Graph.
I need a general code since I have to perform this experiment 20 times with different random points. Please help.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 16 de En. de 2015
The question of plotting and colors was already answered in http://www.mathworks.com/matlabcentral/answers/170028#answer_164948. To answer your current question "How can I extract the values from text file and use it as position for rectangles?" it would be most helpful if you attached the data file and original image like Geoff asked. Make it easy for us to help you. If it's easy we might write code, otherwise we might just give written "directions."

Más respuestas (1)

D. Ali
D. Ali el 27 de Abr. de 2019
I have similar question where I need to extarct all MCAP with time they occured on in separat file and plot if possilbe
I attached the file

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by