MATLAB 视频Gamma灰度校正 自适应中值滤波代码实现
时间: 2023-08-03 18:03:57 浏览: 112
视频Gamma灰度校正代码实现:
```matlab
clc;
clear all;
close all;
% 读取视频
v = VideoReader('test_video.mp4');
% 获取视频帧率
fps = v.FrameRate;
% 创建视频写入对象
writerObj = VideoWriter('gamma_correction_video.avi', 'Uncompressed AVI');
writerObj.FrameRate = fps;
open(writerObj);
while hasFrame(v)
% 读取视频帧
frame = readFrame(v);
% 进行Gamma灰度校正,gamma值为0.5
gamma = 0.5;
frame = imadjust(frame, [], [], gamma);
% 写入视频帧
writeVideo(writerObj, frame);
end
% 关闭视频写入对象
close(writerObj);
```
自适应中值滤波代码实现:
```matlab
clc;
clear all;
close all;
% 读取视频
v = VideoReader('test_video.mp4');
% 获取视频帧率
fps = v.FrameRate;
% 创建视频写入对象
writerObj = VideoWriter('adaptive_median_filter_video.avi', 'Uncompressed AVI');
writerObj.FrameRate = fps;
open(writerObj);
while hasFrame(v)
% 读取视频帧
frame = readFrame(v);
% 进行自适应中值滤波,窗口大小为3x3
frame = medfilt2(frame, [3 3]);
% 写入视频帧
writeVideo(writerObj, frame);
end
% 关闭视频写入对象
close(writerObj);
```
注意:以上代码仅供参考,实际使用时需要根据具体情况进行调整。
阅读全文