当前位置:网站首页>[learning notes] matlab self compiled image convolution function
[learning notes] matlab self compiled image convolution function
2022-07-02 07:52:00 【Silent clouds】
Image convolution principle
Code
% Convolution function
%made by yao
function result = myconv(kernel,img)
[k,num] = size(kernel);
% Determine whether the passed in array is double precision floating-point , Otherwise, type conversion
if ~isa(img,'double')
p1 = double(img);
else
p1 = img;
end
% Extract dimensions
[m,n] = size(p1);
% Construct the template after convolution
% Here we consider the problem of edges , So the black edge was cut off
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
Here's an example , For example, we have 3x3 Convolution kernel , Convolute the image , So in (1,1) When , It will be associated with the outside of the image edge ( Including the upper row and the left column , Similarly, the same situation will appear at the bottom and right of the image ).
So to avoid this , Will the 3x3 The starting point of convolution is set at (2,2) It's about . If the image has m Column n That's ok , Then the convolution of one line terminates in n-1 Out , The convolution end point of a column is m-1 It's about .
Empathy ,5x5 And longer convolution kernels are the same operation .
5x5 The convolution kernel of starts at (3,3), Termination point (m-2,n-2).
So for odd convolution kernels , Let the length of convolution kernel be k, Then the initial convolution point is ((k-1)/2+1), Termination point (m-(k-1)/2)( The ranks are the same , Just change it ).
边栏推荐
- Implementation of yolov5 single image detection based on onnxruntime
- PHP returns the corresponding key value according to the value in the two-dimensional array
- Faster-ILOD、maskrcnn_ Benchmark trains its own VOC data set and problem summary
- MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning
- Faster-ILOD、maskrcnn_benchmark训练coco数据集及问题汇总
- 【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
- [binocular vision] binocular correction
- What if the laptop can't search the wireless network signal
- Win10 solves the problem that Internet Explorer cannot be installed
- iOD及Detectron2搭建过程问题记录
猜你喜欢
mmdetection训练自己的数据集--CVAT标注文件导出coco格式及相关操作
Use Baidu network disk to upload data to the server
【MobileNet V3】《Searching for MobileNetV3》
Faster-ILOD、maskrcnn_ Benchmark installation process and problems encountered
Execution of procedures
Faster-ILOD、maskrcnn_benchmark训练coco数据集及问题汇总
iOD及Detectron2搭建过程问题记录
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
[binocular vision] binocular correction
How to turn on night mode on laptop
随机推荐
【深度学习系列(八)】:Transoform原理及实战之原理篇
Yolov3 trains its own data set (mmdetection)
Latex formula normal and italic
【双目视觉】双目矫正
Remplacer l'auto - attention par MLP
Point cloud data understanding (step 3 of pointnet Implementation)
【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
Faster-ILOD、maskrcnn_benchmark训练自己的voc数据集及问题汇总
iOD及Detectron2搭建过程问题记录
《Handwritten Mathematical Expression Recognition with Bidirectionally Trained Transformer》论文翻译
The difference and understanding between generative model and discriminant model
Generate random 6-bit invitation code in PHP
Common CNN network innovations
Network metering - transport layer
What if the laptop task manager is gray and unavailable
【双目视觉】双目立体匹配
生成模型与判别模型的区别与理解
jetson nano安装tensorflow踩坑记录(scipy1.4.1)
Convert timestamp into milliseconds and format time in PHP
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》