当前位置:网站首页>【学习笔记】Matlab自编图像卷积函数
【学习笔记】Matlab自编图像卷积函数
2022-07-02 06:26:00 【寂云萧】
图像卷积原理

代码
%卷积函数
%made by yao
function result = myconv(kernel,img)
[k,num] = size(kernel);
%判断传入的数组是否为双精度浮点型,否则进行类型转换
if ~isa(img,'double')
p1 = double(img);
else
p1 = img;
end
%提取尺寸
[m,n] = size(p1);
%构造卷积之后的模板
%这里考虑到边缘的问题,所以把黑边裁剪掉了
result = zeros(m-k+1,n-k+1);
for i = ((k-1)/2+1):(m-(k-1)/2)
for j = ((k-1)/2+1):(n-(k-1)/2)
result(i-(k-1)/2,j-(k-1)/2) = sum(sum(kernel .* p1(i-(k-1)/2:i+(k-1)/2,j-(k-1)/2:j+(k-1)/2)));
end
end
end
这里举个例子,比方说我们有3x3的卷积核,对图像进行卷积,那么在(1,1)的时候,就会连带着对图像边缘外面(包括上边一行和左边的一列,同理图像下边和右边也会出现同样的情况)。
所以为了避免这种情况,就要把3x3的卷积核卷积的起始点定在(2,2)处。若图像有m列n行,那么一行的卷积终止出就在n-1出,一列的卷积终止点在m-1处。
同理,5x5以及更长的卷积核也是同样的操作。
5x5的卷积核起始点在(3,3),终止点(m-2,n-2)。
所以对于奇数的卷积核,设卷积核长度为k,那么起始卷积点就是((k-1)/2+1),终止点(m-(k-1)/2)(行列都是一样的,换一下就好)。
边栏推荐
- 【多模态】CLIP模型
- 【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
- Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"
- mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
- 【双目视觉】双目矫正
- Sorting out dialectics of nature
- 【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
- Implementation of yolov5 single image detection based on onnxruntime
- 基于pytorch的YOLOv5单张图片检测实现
- [CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
猜你喜欢

Semi supervised mixpatch
![[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video](/img/bc/c54f1f12867dc22592cadd5a43df60.png)
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video

生成模型与判别模型的区别与理解

Using compose to realize visible scrollbar

【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》

Play online games with mame32k

自然辩证辨析题整理

常见CNN网络创新点

【Random Erasing】《Random Erasing Data Augmentation》

What if the laptop task manager is gray and unavailable
随机推荐
【Programming】
open3d环境错误汇总
Tencent machine test questions
win10解决IE浏览器安装不上的问题
【Programming】
Thesis writing tip2
Comparison of chat Chinese corpus (attach links to various resources)
The difference and understanding between generative model and discriminant model
PHP returns the abbreviation of the month according to the numerical month
(15) Flick custom source
【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
程序的执行
Faster-ILOD、maskrcnn_ Benchmark training coco data set and problem summary
ABM论文翻译
TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
半监督之mixmatch
点云数据理解(PointNet实现第3步)
Implementation of yolov5 single image detection based on onnxruntime
Traditional target detection notes 1__ Viola Jones
Win10 solves the problem that Internet Explorer cannot be installed