当前位置:网站首页>【学习笔记】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)(行列都是一样的,换一下就好)。
边栏推荐
- Two dimensional array de duplication in PHP
- [binocular vision] binocular correction
- 【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
- 传统目标检测笔记1__ Viola Jones
- Interpretation of ernie1.0 and ernie2.0 papers
- Point cloud data understanding (step 3 of pointnet Implementation)
- One book 1078: sum of fractional sequences
- Mmdetection trains its own data set -- export coco format of cvat annotation file and related operations
- 【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
- How to turn on night mode on laptop
猜你喜欢
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
Using compose to realize visible scrollbar
Semi supervised mixpatch
【Programming】
Use Baidu network disk to upload data to the server
Implementation of yolov5 single image detection based on pytorch
[binocular vision] binocular correction
Mmdetection installation problem
Drawing mechanism of view (I)
Faster-ILOD、maskrcnn_ Benchmark installation process and problems encountered
随机推荐
【Random Erasing】《Random Erasing Data Augmentation》
【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"
Win10+vs2017+denseflow compilation
Record of problems in the construction process of IOD and detectron2
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
Mmdetection model fine tuning
Point cloud data understanding (step 3 of pointnet Implementation)
深度学习分类优化实战
Alpha Beta Pruning in Adversarial Search
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
[in depth learning series (8)]: principles of transform and actual combat
A slide with two tables will help you quickly understand the target detection
Faster-ILOD、maskrcnn_benchmark安装过程及遇到问题
CONDA common commands
【Paper Reading】
open3d学习笔记五【RGBD融合】
Correction binoculaire
MMDetection安装问题
【Random Erasing】《Random Erasing Data Augmentation》