当前位置:网站首页>MATLAB image processing -- image transformation correction second-order fitting
MATLAB image processing -- image transformation correction second-order fitting
2022-06-12 08:06:00 【HNU_ Liu Yuan】
Second order fitting of image transformation correction
Problem description
Two adjacent images in a known sequence of images A(up.jpg)、B(down.jpg), The coordinates are (u,v) And (x,y), Try to find the coefficients of the second-order fitting equation for image transformation correction K. It is required to solve by the least square method , The transformation model is :
up.jpg:
down.jpg:
Methods described


The process
Firstly, coordinates of the points corresponding to distortion and reference image before and after transformation are obtained :
Distorted image coordinates :
- x=[300 386 293 498 369 384 52]
- y=[483 441 285 288 125 38 138]
The corresponding coordinates of the reference image : - u=[99 69 254 121 326 381 510]
- v=[63 141 174 312 331 398 93]
The coefficients of the corrected second-order fitting equation are solved by the least square method , Solve to get K:
namely :
X= 619 – 0.597u – 0.532v + 0.0001u^2 - 0.0001v^2 – 0.0004uv
Y= 133+0.756u – 0.572v + 0.0004u^2 + 0.0007v^2 – 0.0004uv
result
First, the transformed image size is obtained through coordinate transformation , And initialize a matrix , As a transformed matrix , The image pixel value is mapped by the obtained corrected second-order fitting equation , The final image is as follows :
As can be seen from the above image , To be changed down Images . After transformation matrix mapping , The general direction of the image and the image to be mapped up Almost the same , But the size of the mapped image has also changed , The changed image cannot be completely filled , The straight lines in the original drawing may not be straight lines after transformation .
Code
clc
clear all
img_down = imread('down.jpg');
subplot(1,3,1)
imshow(img_down);
title("down");
img_up = imread('up.jpg');
subplot(1,3,2);
imshow(img_up);
title("up");
[h,w,c] = size(img_down);
% Distorted image coordinates
x=[300 386 293 498 369 384 52]'; y=[483 441 285 288 125 38 138]';
% Reference image coordinates
u=[99 69 254 121 326 381 510]'; v=[63 141 174 312 331 398 93]';
% The least square method
P=[x,y];
a=[1 1 1 1 1 1 1]'; U=[a, u, v, u.^2, v.^2, (u.*v)]; K_xy=inv(U'*U)*U'*P P=[u,v]; U=[a,x,y,x.^2,y.^2,(x.*y)]; K_uv=inv(U'*U)*U'*P
ver_xy = [1,1; 1,w; h,1; h,w]; % down.jpg Four vertices of
ver_data = [ones(4, 1), ver_xy, ver_xy(:,1).^2, ver_xy(:,2).^2, ver_xy(:,1).*ver_xy(:,2)];
ver_t = ver_data*K_xy; % Vertex coordinates after coordinate conversion
ver_t_max = ceil(max(ver_t));
ver_t_min = floor(min(ver_t));
size_t = ver_t_max - ver_t_min + 1;
down_t = zeros(size_t(1), size_t(2), 3); % 0 Initialize the converted image
% The output image position of this part is offset , Need to reconsider the size of the picture
for u=ver_t_min(1):ver_t_max(1)
for v=ver_t_min(2):ver_t_max(2)
d = [1, u, v, u^2, v^2, u*v];
pos = round(d*K_uv); % Find the corresponding by inverse transformation down.jpg Middle coordinates
if pos(1)>=1 && pos(2)>=1 && pos(1) <= h && pos(2) <= w
down_t(u-ver_t_min(1)+1, v-ver_t_min(2)+1, :) = img_down(pos(1), pos(2), :);
end
end
end
down_t = uint8(down_t);
subplot(1,3,3)
imshow(down_t);
title("down to up");
边栏推荐
- Mathematical knowledge - derivation - Basic derivation knowledge
- MSE (mean square error) calculation package function
- Vision Transformer | Arxiv 2205 - TRT-ViT 面向 TensorRT 的 Vision Transformer
- Compiling principle on computer -- functional drawing language (V): compiler and interpreter
- Compiling principle on computer -- functional drawing language (IV): semantic analyzer
- Topic 1 Single_ Cell_ analysis(2)
- Web page performance optimization interview questions
- 20220607. face recognition
- 802.11 protocol: wireless LAN protocol
- 『Three.js』辅助坐标轴
猜你喜欢

模型压缩 | TIP 2022 - 蒸馏位置自适应:Spot-adaptive Knowledge Distillation

『Three.js』辅助坐标轴

Literature reading: raise a child in large language model: rewards effective and generalizable fine tuning

PPP agreement

Dynamic simulation method of security class using Matlab based Matpower toolbox

DUF:Deep Video Super-Resolution Network Using Dynamic Upsampling Filters ...阅读笔记

(P40-P41)move资源的转移、forward完美转发

Getting started with Jetson nano Series IV: common skills of NVIDIA Jetson nano

Derivation of Poisson distribution

Final review of Discrete Mathematics (predicate logic, set, relation, function, graph, Euler graph and Hamiltonian graph)
随机推荐
Compiling principle on computer -- function drawing language (II): lexical analyzer
Cmake can't find the solution of sophus
Clarify the division of IPv4 addresses
The R language uses the sample The split function divides the machine learning data set into training set and test set
Windows10 configuration database
Principes et exemples de tâches OpenMP
JSP technology
Leetcode notes: Weekly contest 278
Transformation from AC5 to AC6 (1) - remedy and preparation
Quaternion Hanmilton and JPL conventions
Kalman filter encapsulation function
2021.10.26 scientific research log
Servlet advanced
从AC5到AC6转型之路(1)——补救和准备
Pytorch practice: predicting article reading based on pytorch
The latest hbuilderx editing uni app project runs in the night God simulator
Literature reading: raise a child in large language model: rewards effective and generalizable fine tuning
Introduction to coco dataset
Vision Transformer | Arxiv 2205 - LiTv2: Fast Vision Transformers with HiLo Attention
2、 Eight, ten and hexadecimal conversion