How to extract a vector from an image?
Mostrar comentarios más antiguos
Hello,
I have this image

and I want to extract only the velocity vector from the image. Is there a code to do so?
Thank you in advance
2 comentarios
Walter Roberson
el 21 de Feb. de 2017
Do you mean that you want to do optical character recognition to read the '43.6406' ?
Efstathios Kontolatis
el 21 de Feb. de 2017
Respuesta aceptada
Más respuestas (2)
Walter Roberson
el 21 de Feb. de 2017
0 votos
The blue vector is the only area in which:
- blue is notably greater than 0;
- and red is low
Red is low in the black sections near the edges, but blue is low for those.
Blue is notably greater than 0 for the grey and white portions, but red is not low for those.
9 comentarios
Efstathios Kontolatis
el 21 de Feb. de 2017
Walter Roberson
el 21 de Feb. de 2017
img = imread('1.png');
R = img(:,:,1);
B = img(:,:,3);
r_thresh = 20; %a guess
b_thresh = 50; %a guess
mask = R < r_thresh & B > b_thresh;
mask3 = mask(:,:,[1 1 1]);
masked_image = zeros(size(img), class(img));
masked_image(mask3) = img(mask3);
Efstathios Kontolatis
el 21 de Feb. de 2017
Walter Roberson
el 21 de Feb. de 2017
Efstathios Kontolatis
el 21 de Feb. de 2017
Walter Roberson
el 22 de Feb. de 2017
... then you throw away everything that is not a digit or '.' and you convert the string that remains to a double?
Or you could
velocity = sscanf(TheString, 'v=%f')
which would do the conversion for you, assuming it really was able to figure out the literal 'v' and literal '=' and did not add any spacing. It is safer to assume it might have gotten those wrong.
Image Analyst
el 22 de Feb. de 2017
Who created that image? Was it your code? Or someone else's? Why not just ask them to output the vector endpoints and number? If you're stuck with the annotated RGB image then you'll need to do as Walter says but only if you have hundreds of images, otherwise you'll spend less time just using ginput(2) to get the endpoints and typing the number you see into inputdlg(), unless you want to write the code just for the fun of it Actually getting the all the points along the blue line is easy with Walter's code - it's the OCR that is the hard part if you don't have the Computer Vision System Toolbox.
Efstathios Kontolatis
el 10 de Mzo. de 2017
Walter Roberson
el 10 de Mzo. de 2017
Try thresholding in the bounding box of the text and inverting to turn the text from black to white.
Image Analyst
el 10 de Mzo. de 2017
You started with just an image, then you found the outline somehow, and used plot(x,y,'g-') to plot the green outline, and you probably used annotation() to draw the blue arrow. Then you used
vText = sprintf('v=%.4fm/s', v);
text(x, y, vText, 'Color', 'k', 'BackgroundColor', 'y');
You had to do that because the text won't just magically appear in the image. So you already know what v is. If you don't, then explain how the yellow text got there.
Categorías
Más información sobre Image Processing and Computer Vision en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
