フィルターのクリア

How to extract a vector from an image?

7 ビュー (過去 30 日間)
Efstathios Kontolatis
Efstathios Kontolatis 2017 年 2 月 21 日
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 件のコメント
Walter Roberson
Walter Roberson 2017 年 2 月 21 日
Do you mean that you want to do optical character recognition to read the '43.6406' ?
Efstathios Kontolatis
Efstathios Kontolatis 2017 年 2 月 21 日
Firstly I want to obtain just the vector(blue). Then yes I would like to do the optical recognition to read the value of the velocity vector.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 3 月 10 日
Try this
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 15;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = '1.png';
% Get the full filename, with path prepended.
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%===============================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
[imageRows, imageColumns, numberOfColorChannels] = size(rgbImage);
% Display the original image.
subplot(1, 3, 1);
imshow(rgbImage, []);
axis on;
caption = sprintf('Original Color Image, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Threshold to get the blue mask.
yellowMask = redChannel > 150 & greenChannel > 150 & blueChannel < 150;
% Fill it.
yellowMask = imfill(yellowMask, 'holes');
% Display the image.
subplot(1, 3, 2);
imshow(yellowMask);
grid on;
axis on;
title('Yellow Mask Image', 'FontSize', fontSize);
% Find boundingBox
props = regionprops(yellowMask, 'BoundingBox');
croppedImage = imcrop(rgbImage, props.BoundingBox);
% Display the image.
subplot(1, 3, 3);
imshow(croppedImage);
axis on;
caption = sprintf('Final, Cropped Image');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
  1 件のコメント
Efstathios Kontolatis
Efstathios Kontolatis 2017 年 3 月 12 日
Thanks a lot that works fine

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2017 年 2 月 21 日
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 件のコメント
Efstathios Kontolatis
Efstathios Kontolatis 2017 年 3 月 10 日
I have the Computer Vision System Toolbox. Also I have produced these images manually but unfortunately I didn't think of what I will do next with the text. How can I output the vector endpoints and the number? Unfortunately the ocr doesn't work it gives me completely blank char.
Walter Roberson
Walter Roberson 2017 年 3 月 10 日
Try thresholding in the bounding box of the text and inverting to turn the text from black to white.

サインインしてコメントする。


Image Analyst
Image Analyst 2017 年 3 月 10 日
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.

Community Treasure Hunt

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

Start Hunting!

Translated by