Image analysis - line to value data plotting

8 views (last 30 days)
BG Kim
BG Kim on 9 May 2016
评论: Image Analyst 2016年5月11日
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.

答案(2)

Alessandro Masullo
Alessandro Masullo on 9 May 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条评论
Image Analyst
Image Analyst 2016年5月10日
你可以做
[rows, columns] = find(im < 128);
并跳过不需要的sub2ind()函数(无论如何这是错误的,因为它应该是Ind2sub),但是您 accepted 这个答案所以您终于使它起作用了吗?

登录发表评论。


Image Analyst
Image Analyst 2016年5月10日
这真的是您想要的:
% Get coordinates of a black line in a white image.
CLC;%清除命令窗口。
关闭all;% Close all figures (except those of imtool.)
清除;%删除所有现有变量。或Clearvars如果需要。
工作区;% Make sure the workspace panel is showing.
为了matlong g;
为了matcompact;
fontSize = 20;
% Get the base filename.
basefilename ='data.jpg';%分配他们单击的按钮上的一个。
%获取完整的文件名,并准备了路径。
文件夹= pwd;当前文件夹%
FullFileName = fullFile(文件夹,basefileName);
%检查文件是否存在。
if〜存在(FullFileName,'文件'
%文件不存在 - 在那里找不到它。检查搜索路径。
fullFileNameonSearchPath = basefileName;% No path this time.
if~exist(fullFileNameOnSearchPath,'文件'
% Still didn't find it. Alert user.
errormessage = sprintf(“错误:%s在搜索路径文件夹中不存在。”,,,,fullFileName);
UIWAIT(warndlg(errormessage));
return;
结尾
结尾
%阅读图像。
grayImage = imread(fullFileName);
% Get the dimensions of the image.
百分比的颜色冠状器应为= 1。
[行,列,numberOfColorBands] = size(grayimage);
if数字颜色> 1
% It's not really gray scale like we expected - it's color.
%将其转换为灰度,仅采用绿色通道。
灰色映射= min(灰色图,[],3);% Take green channel.
结尾
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
axison;
title(“原始灰度图像”,,,,'字体大小', 字体大小,'Interpreter',,,,'没有任何');
drawnow;
% Set up figure properties:
%放大的数字到全屏。
设置(GCF,'Units',,,,“Normalized',,,,'OuterPosition',,,,[0 0 1 1]);
%可以摆脱沿着图形顶部的工具栏和下拉菜单。
设置(GCF,“工具栏”,,,,'没有任何',,,,'菜单',,,,'没有任何');
% Give a name to the title bar.
设置(GCF,'姓名',,,,“成像分析师的演示”,,,,'numberTitle',,,,'Off'
%让我们计算并显示直方图。
subplot(2, 2, 2);
直方图(灰色图);
gridon;
title('Histogram of original image',,,,'字体大小', 字体大小,'Interpreter',,,,'没有任何');
xlabel('Gray Level',,,,'字体大小', 字体大小);
ylabel(“像素计数”,,,,'字体大小', 字体大小);
% Threshold to find dark.
二进制图=灰色图<128;
%斑点必须至少是一定数量的像素。
二进制图= bwareaopen(二进制图,30);
% Display the binary image.
次要情节(2、2、3);
imshow(二进制图,[]);
axison;
抓住on;%因此我们可以画盒子。
title('Binary Image',,,,'字体大小', 字体大小,'Interpreter',,,,'没有任何');
drawnow;
%逐列穿过,获取平均行值。
rowValues = zeros(1, columns);%初始化
为了col = 301:列
thisColumn = binaryImage(:, col);
rows = find(thisColumn);
if〜iSempty(行)
rowValues(col) = mean(rows);
结尾
结尾
子图(2,2,4);
plot(rowValues,'b-',,,,'行宽',2);
gridon;
2条评论
Image Analyst
Image Analyst 2016年5月11日
我给你。他们在可变的rowvalues中。RowValues的元素(索引)是列编号,RowValues是该列线所在的图像中的行。像第123列一样,该行在Rowvalues(123)。

登录发表评论。

社区Treasure Hunt

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!