当前位置:网站首页>[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 ).
边栏推荐
- 【Mixup】《Mixup:Beyond Empirical Risk Minimization》
- Ppt skills
- Faster-ILOD、maskrcnn_ Benchmark installation process and problems encountered
- 【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
- Win10+vs2017+denseflow compilation
- A slide with two tables will help you quickly understand the target detection
- Common CNN network innovations
- Mmdetection installation problem
- 【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
- Machine learning theory learning: perceptron
猜你喜欢

【MagNet】《Progressive Semantic Segmentation》

How do vision transformer work?【论文解读】

MoCO ——Momentum Contrast for Unsupervised Visual Representation Learning

【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》

论文写作tip2

联邦学习下的数据逆向攻击 -- GradInversion

【Batch】learning notes

Common machine learning related evaluation indicators

jetson nano安装tensorflow踩坑记录(scipy1.4.1)

A slide with two tables will help you quickly understand the target detection
随机推荐
Feature Engineering: summary of common feature transformation methods
【MobileNet V3】《Searching for MobileNetV3》
Common machine learning related evaluation indicators
Regular expressions in MySQL
CPU register
【深度学习系列(八)】:Transoform原理及实战之原理篇
[binocular vision] binocular correction
【双目视觉】双目立体匹配
半监督之mixmatch
Drawing mechanism of view (3)
(15) Flick custom source
Latex formula normal and italic
What if the laptop can't search the wireless network signal
win10+vs2017+denseflow编译
How do vision transformer work? [interpretation of the paper]
【Mixed Pooling】《Mixed Pooling for Convolutional Neural Networks》
Faster-ILOD、maskrcnn_ Benchmark installation process and problems encountered
MMDetection安装问题
Comparison of chat Chinese corpus (attach links to various resources)
[binocular vision] binocular stereo matching