Image analysis - line to value data plotting
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How can I open the image (jpg, etc) at the MATLAB? How can I get the line data value from the image like below? I want to plot the data of the line in the image. Normalized data is okay.
0 Commenti
Risposte (2)
Alessandro Masullo
il 9 Mag 2016
You can use imread to read the image. If your image is already normalized, you can use find to get the elements of the line. Being the line black on a white background, you need to invert it by using ~.
im = imread(...);
f = find(~im);
[y,x] = sub2ind(...)
2 Commenti
Image Analyst
il 10 Mag 2016
You can do
[rows, columns] = find(im < 128);
and skip the unneeded sub2ind() function (which was wrong anyway because it should have been ind2sub), but you accepted this Answer so did you finally get it working?
Image Analyst
il 10 Mag 2016
Is this really what you want:
% Get coordinates of a black line in a white image.
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 = 20;
% Get the base filename.
baseFileName = 'data.jpg'; % Assign the one on the button that they clicked on.
% Get the full filename, with path prepended.
folder = pwd; % Current folder
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
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 image.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayImage = min(grayImage, [], 3); % Take green channel.
end
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axis on;
title('Original Grayscale Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% 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')
% Let's compute and display the histogram.
subplot(2, 2, 2);
histogram(grayImage);
grid on;
title('Histogram of original image', 'FontSize', fontSize, 'Interpreter', 'None');
xlabel('Gray Level', 'FontSize', fontSize);
ylabel('Pixel Count', 'FontSize', fontSize);
% Threshold to find dark.
binaryImage = grayImage < 128;
% Blobs must be at least a certain number of pixels.
binaryImage = bwareaopen(binaryImage, 30);
% Display the binary image.
subplot(2, 2, 3);
imshow(binaryImage, []);
axis on;
hold on; % So we can draw boxes.
title('Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
% Go across column by column, getting the average row value.
rowValues = zeros(1, columns); % Initialize
for col = 301 : columns
thisColumn = binaryImage(:, col);
rows = find(thisColumn);
if ~isempty(rows)
rowValues(col) = mean(rows);
end
end
subplot(2, 2, 4);
plot(rowValues, 'b-', 'LineWidth', 2);
grid on;
2 Commenti
Image Analyst
il 11 Mag 2016
I give you that. They're in the variable rowValues. The elements (index) of rowValues are the column numbers, and rowValues is the row in the image where the line is for that column. Like for column 123, the line is at rowValues(123).
Vedere anche
Categorie
Scopri di più su Image Processing Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!