Skip to content

Commit

Permalink
将VideoPixelMeasure替换为VideoBatchMeasure,并分离出VideoDrawROI功能
Browse files Browse the repository at this point in the history
  • Loading branch information
埃博拉酱 committed Sep 27, 2021
1 parent f30a882 commit 7890916
Show file tree
Hide file tree
Showing 23 changed files with 268 additions and 1,411 deletions.
2 changes: 1 addition & 1 deletion +ImageProcessing/Version.m
@@ -1,4 +1,4 @@
function V = Version
V.Me='1.0.0';
V.Me='2.0.0';
V.MatlabExtension=MATLAB.Version;
V.MATLAB='R2021b';
Binary file added +ImageProcessing/VideoBatchMeasure.mlx
Binary file not shown.
Binary file added +ImageProcessing/VideoDrawROI.mlx
Binary file not shown.
Binary file removed +ImageProcessing/VideoPixelMeasure.mlx
Binary file not shown.
11 changes: 11 additions & 0 deletions +ImageProcessing/private/ClipMeasure.m
@@ -0,0 +1,11 @@
function Measurement = ClipMeasure(VR,GpuAvailable,VideoMasks,varargin)
Data=VR.read(varargin{:});
if GpuAvailable
Data=gpuArray(Data);
end
Data=single(Data);
if size(Data,3)>1
Data=0.2989*Data(:,:,1,:)+0.5870*Data(:,:,2,:)+0.1140*Data(:,:,3,:);
end
Data=reshape(Data,[],size(Data,4));
Measurement=gather(VideoMasks*Data);
27 changes: 27 additions & 0 deletions +ImageProcessing/private/FileMeasure.m
@@ -0,0 +1,27 @@
function Measurements = FileMeasure(Path,VideoMasks,FreeMemory,GpuAvailable)
VR=VideoReader(Path);
Data=VR.readFrame;
VideoMasks=reshape(VideoMasks,[],size(VideoMasks,3))';
VideoMasks=VideoMasks./sum(VideoMasks,2);
FrameSize=numel(Data)*4;
NoFrames=VR.NumFrames;
if FrameSize*NoFrames<FreeMemory
Measurements=ClipMeasure(VR,GpuAvailable,VideoMasks);
else
ActualBlocks=ceil(NoFrames/floor(FreeMemory/FrameSize));
Frames1=floor(NoFrames/ActualBlocks);
Frames2=Frames1+1;
Blocks1=ActualBlocks*Frames2-NoFrames;
VideoMeasurement=cell(1,ActualBlocks);
ReadRange=[1 Frames1];
for B=1:Blocks1
VideoMeasurement{B}=ClipMeasure(VR,GpuAvailable,VideoMasks,ReadRange);
ReadRange=ReadRange+Frames1;
end
ReadRange(2)=ReadRange(2)+1;
for B=Blocks1+1:ActualBlocks
VideoMeasurement{B}=ClipMeasure(VR,GpuAvailable,VideoMasks,ReadRange);
ReadRange=ReadRange+Frames2;
end
Measurements=[VideoMeasurement{:}];
end
31 changes: 22 additions & 9 deletions README.md
@@ -1,16 +1,29 @@
埃博拉酱的图像处理工具包,提供一系列MATLAB Image Processing Toolbox内置函数所欠缺,但却常用的图像处理功能
埃博拉酱的图像处理工具包,提供一系列MATLAB Image Processing Toolbox内置函数所欠缺,但却常用的图像处理功能。依赖[埃博拉酱的MATLAB扩展](https://ww2.mathworks.cn/matlabcentral/fileexchange/96344-matlab-extension)

本项目的发布版本号遵循[语义化版本](https://semver.org/lang/zh-CN/)规范。开发者认为这是一个优秀的规范,并向每一位开发者推荐遵守此规范。
# 目录
本包中所有函数均在ImageProcessing命名空间下,使用前需import。使用命名空间是一个好习惯,可以有效防止命名冲突,避免编码时不必要的代码提示干扰。
- [VideoPixelMeasure](#VideoPixelMeasure)
# VideoPixelMeasure
视频像素测量
- [VideoBatchMeasure](#VideoBatchMeasure) 根据ROI批量测量视频像素值
- [VideoDrawROI](#VideoDraoROI) 给视频画ROI用于测量
# VideoBatchMeasure
根据ROI批量测量视频像素值
## 输入参数
Flags(1,1)string,重复,可选设置以下功能旗帜:
- Gpu,使用GPU加速计算
- Verbose,输出进度信息
- Parallel,使用并行计算。如果还指定了Gpu,将只在一个进程中使用GPU,其他进程仍使用CPU。

本函数用ROI遮罩测量视频平面上像素值随视频帧的时间变化,彩色计算灰度。
## 名称值参数
VideoPath(1,1)string,视频文件路径。默认打开文件选择对话框供用户手动选择。
VideoPaths(:,1)string,名称值,视频路径,默认打开文件选择对话框要求用户手动选择

Masks(:,:,:)logical,测量遮罩。第1维高度,第2维宽度,第3维不同ROI。默认要求用户手动画圈
Masks(:,1)cell,名称值,测量遮罩。默认调用ImageProcessing.VideoDraoROI要求用户手动绘制
## 返回值
Measurements(:,:)double,测量值。第1维ROI,第2维时间。每个数值是某时刻某ROI的全像素平均值。
Measurements(:,1)cell,每个元胞对应一个视频,元胞内是(:,:)single,第1维ROI,第2维时间帧,每个数值代表该ROI内所有像素在该时间帧内的平均值
Masks(:,1)cell,同输入参数中的Masks。如果你的遮罩是临时手绘的,可以用这个返回值取得遮罩。
# VideoDrawROI
给视频画ROI用于测量
## 输入参数
NoROIs(1,1)uint8,必需,每个视频要画多少个ROI

VideoPaths(:,1)string,可选,所有视频文件路径。默认打开文件选择对话框要求用户手动选择
## 返回值
Masks(:,1)cell,每个视频的测量遮罩,每个元胞对应一个视频。元胞内是(:,:,:)logical,前两维是视频的高宽,第3维是不同的ROI。

This file was deleted.

@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="VideoBatchMeasure.mlx" type="File" />
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design" />
</Category>
</Info>
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="VideoDrawROI.mlx" type="File" />
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design" />
</Category>
</Info>
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="ClipMeasure.m" type="File" />
@@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design" />
</Category>
</Info>
@@ -0,0 +1,2 @@
<?xml version='1.0' encoding='UTF-8'?>
<Info location="FileMeasure.m" type="File" />

0 comments on commit 7890916

Please sign in to comment.