Loren在Matlab的艺术上

将想法转化为matlab

我的胡子在一周内生长多久了?

冒险的思想弯曲的故事。一种温和令人争论的纱线。
今天的客人博客是罗茨·霍尔特,他在马萨诸塞州纳尼克的Mathworks工作。
Rob目前是Manager for Biological Sciences at MathWorks. He is a coordinator and collaborator for biology, biotech, and pharmaceutical applications. Previously, Rob spent five years as a Senior Scientist at Invicro, a Konica Minolta company, where he designed, implemented, and communicated image analysis algorithms for drug discovery and development. Rob earned his PhD at Dartmouth College, where he focused on molecular cancer imaging through multimodal medical image synthesis. Follow more of Robÿs antics on 他的推特 他的linkedin
我上周末修剪了我的胡子。虽然我的思绪由于缺乏附近的计算设备而徘徊,但我以为“我的胡子头发的快速成长?”这是我无法思考的想法之一。所以我开始计划了。
我认为我可以让它增长一个月,然后使用统治者来衡量,但那么我可能会从干净的剃须中挣扎,牺牲我留下的职业技术。
Then inspiration struck. Trim the beard, let it grow for exactly a week, then trim the beard again to the same length. If we have a picture of the trimmed hairs, and something in the picture that is of known size, we can extract some kind of length information. Brilliant!

阅读并显示图像

%加载图像
imname =.'mysink.jpg';
im = imread(imname);
数字;
imshow (im);
标题('原始图像​​');
请注意,视野中有一分钱。我扔在水槽中的原因是一分钱的直径很好地定义为19.05mm。这用作已知的参考,以稍后确定像素大小。这也是我能负担得起的。

使用PENNY获取像素大小

功能 imfindcircles. can be used to find circular objects in the field of view. Note that I have a rough estimate of the radius range, and that since the penny is darker than the background, we set the object polarity to be dark.
%裁剪了关于便士的图像
PennyImage = IM(1400:1800,1000:1500,:);
%过滤便士图像一点
PennyImagefilt = Medfilt3(PennyImage,[15 15 1]);
%使用imfindcircles功能来找到便士
拉伸= [100 300];
[中心,radii] = imfindcircles(PennyImagefilt,Radrange,......
'objectpolarity''dark');
%可视化找到的所有圆圈
数字;
imshow(PennyImage)
Viscircles(中心,半径,'Edgecolor''B');
标题('Penny Detail With Circle Annotation');
%计算PENNY半径的像素大小
%使用mm直径/像素直径
psize = 19.05 /(radii(1)* 2);%像素大小为mm
FPRINTF('像素大小为%d microns \ n',圆形(psize * 1000))
像素尺寸为62微米

分割毛发

现在我们有像素尺寸,我们可以分割头发并试图找到它们的长度。为了保持更简单的事情,让我们播出一部只是头发。
Justhair = IM(500:1800,1500:3000,:);
数字;
subplot(121)
imshow(justhair);
标题('只是头发');
subplot(122)
imshow(justhair(150:500,900:1350,:));
标题('头发上的细节');
现在我们需要从背景中分割头发。由于头发是黑暗的,背景是白色的,这相当简单。这也可以在灰度图像上完成,因为颜色并不真正将任何信息添加到此任务。
grayHair = rgb2gray(justHair);
数字;
subplot(121)
imshow(灰色髻);
标题('我的灰色头发');
subplot(122)
imshow(灰色髻(150:500,900:1350))
标题(“灰色头发上的细节”);
希望这是未来几年我唯一的灰色头发。
现在我们可以使用经典的OTSU阈值,它根据强度自动将图像分为两个类。这可以使用命令完成 塔布林 ,这决定了将两个类与强度分开的阈值, imbinarize. ,它使用该阈值来制作二进制图像。
thresh = twaythresh(灰毛);
发桥=〜Imbinarize(灰色,阈值);
数字;
subplot(121)
imshow(发型);
标题('头发细分');
subplot(122)
imshow(发型(150:500,900:1350));
标题(“头发细分”细节'的)
在这种情况下, imbinarize. makes the brighter part "true", so the is to logically flip that to make the hair part of 发桥 那the segmentation of the hair, to be 真的

试着保持不懈的毛发

现在我们有所有的毛发。其中一些是丛中的,但大多数都看起来像是独立的。对于第一次通过估计,让我们去除较大的簇,以及较小的簇,留下大多是独特的毛发。
%删除了在边境被切断的任何毛发
Beaeseg = Imclearborder(Bairseg);
%删除了太小的簇
Bairseg = Bwareaopen(发型,30);
%删除太大的群集
发桥=发桥&〜Bwareaopen(发尾,300);
数字;
subplot(121)
imshow(发型)
标题('Hairs Examined for Length');
subplot(122)
imshow(发型(150:500,900:1350))
标题(在毛发上拍摄的细节');

估计所有毛发的长度

We have a segmentation of the best hairs for us to examine now. What we can do to estimate their length is first skeletonize (make each hair at most one pixel wide), and then count the pixels in each skeletonized hair. This is done using the property "area", but since each hair is one pixel wide, the area is roughly equal to the length of the hair.
%骨骼发毛发
hairSkel = bwskel(hairSeg);
%show the skeleton
数字;
subplot(121)
imshow(发型);
标题('头发骨架化');
subplot(122)
imshow(发型(150:500,900:1350));
标题('Detail on Hair Skeletonization');
%计算所有毛发的长度
统计= RegionProps(发型,'区域');
%让地区摆脱困境
hairLengthInPixels = cat(1,stats.Area);
百分比变换到现实世界长度
Hairlength = hairlengthinpixels * psize;

计算平均头发长度

所以现在我们有一个所有毛发的长度列表。因此,我们可以可视化直方图以及计算平均长度。
数字;
直方图(发型);
xlabel('头发长度(mm)');
ylabel('Number of Hairs');
meanhairlength =均值(发型);
FPRINTF('平均头发长度:%.1fmm \ n',意思是尺寸);
平均头发长度:2.2mm

摘要和讨论

So that's it! My beard hair grows about 2.2mm a week, or about 0.31mm per day. That is very close to 吉列估计每天0.27毫米
当然,这个模型并不完美。通过将曲线拟合到每条头发,可以更准确。如果我们找到了分离更多较大的毛发的方法,分割可能更准确。但是对于大多数实用的目的,这将是一个很好的估计。
这种工作流还可以应用于其他图像处理方案。例如,测量生命科学研究中的毛虫或蠕虫的长度,或测量工业制造质量控制的碎片长度。
你最近有过奇怪的项目吗?你知道你可以在这种问题上使用matlab吗?您认为我的胡子头发的高分辨率图片是不合适的吗?请在评论中分享您的想法和意见 here
版权所有2021 MathWorks,Inc。
|

评论

要发表评论,请点击here要登录您的MathWorks帐户或创建新的。