当前位置:网站首页>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");
边栏推荐
- Servlet
- Symfony 2: multiple and dynamic database connections
- 2D visualization of oil storage, transportation and production, configuration application enables intelligent development of industry
- Vision Transformer | Arxiv 2205 - LiTv2: Fast Vision Transformers with HiLo Attention
- Cookies and sessions
- MinGW offline installation package (free, fool)
- Vision Transformer | CVPR 2022 - Vision Transformer with Deformable Attention
- Meter Reading Instrument(MRI) Remote Terminal Unit electric gas water
- FPGA based communication system receiver [packet detection] development document
- Numerical calculation method chapter6 Iterative method for solving linear equations
猜你喜欢

Servlet

Vision Transformer | Arxiv 2205 - TRT-ViT 面向 TensorRT 的 Vision Transformer

Topic 1 Single_Cell_analysis(2)

Windows10 configuration database

Model Trick | CVPR 2022 Oral - Stochastic Backpropagation A Memory Efficient Strategy

Vision Transformer | Arxiv 2205 - LiTv2: Fast Vision Transformers with HiLo Attention

Explain the basic working principle of Ethernet

20220526 yolov1-v5

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

Rich dad, poor dad Abstract
随机推荐
El expression and JSTL
Introduction to coco dataset
Leetcode notes: biweekly contest 79
Compiling principle on computer -- functional drawing language (V): compiler and interpreter
解决逆向工程Mapper重复问题
Leetcode notes: Weekly contest 279
Latex usage problems and skills summary (under update)
Database connection pool and dbutils tool
tmux常用命令
DUF:Deep Video Super-Resolution Network Using Dynamic Upsampling Filters ...阅读笔记
Pytorch installation (GPU) in Anaconda (step on pit + fill pit)
AJ project: online bank project summary
Principes et exemples de tâches OpenMP
OpenMP task 原理與實例
Alibaba cloud deploys VMware and reports an error
Explanation and explanation on the situation that the volume GPU util (GPU utilization) is very low and the memory ueage (memory occupation) is very high during the training of pytoch
2021.11.2 scientific research log
Meter Reading Instrument(MRI) Remote Terminal Unit electric gas water
Summary of structured slam ideas and research process
Conda創建虛擬環境報錯,問題解决