function LK2
im1 = imread('image1.png');
im2 = imread('image2.png');
result2 = im2;
figure,imshow(im1);
figure,imshow(im2);
image1=single(rgb2gray(im1));
image2=single(rgb2gray(im2));
Levels=3;
window=15;
k=4;
half = floor(window/2);
temp1 = image1;
temp2 = image2;
for i=2:Levels
image1 = impyramid(image1, 'reduce');
image2 = impyramid(image2, 'reduce');
temp1(1:size(image1,1), 1:size(image1,2), i) = image1;
temp2(1:size(image2,1), 1:size(image2,2), i) = image2;
end;
for p = 1:Levels
qq = Levels - p;
image1 = temp1(1:(size(temp1,1)/(2^qq)), 1:(size(temp1,2)/(2^qq)),qq+1);
image2 = temp2(1:(size(temp2,1)/(2^qq)), 1:(size(temp2,2)/(2^qq)),qq+1);
if p==1
u=zeros(size(image1));
v=zeros(size(image1));
else
u = 2*imresize(u,size(u)*2,'bicubic');
v = 2*imresize(v,size(v)*2,'bicubic');
end
[dx1,dy1] = gradient(image1);
[dx2,dy2] = gradient(image2);
for r=1:1:k
u=round(u);
v=round(v);
for i = 1+half:size(image1,1)-half
for j = 1+half:size(image2,2)-half
picture1 = image1(i-half:i+half,j-half:j+half);
up = i-half+v(i,j);
down = i+half+v(i,j);
left = j-half+u(i,j);
right = j+half+u(i,j);
if (up<1)||(down>size(image1,1))||(left<1)||(right>size(image1,2))
continue;
else
picture2 = image2(up:down, left:right);
dxtemp = (dx1(i-half:i+half,j-half:j+half)+dx2(up:down,left:right))/2;
dytemp = (dy1(i-half:i+half,j-half:j+half)+dy2(up:down,left:right))/2;
dt = picture2 - picture1;
A = [dxtemp(:) dytemp(:)];
M=-(pinv(A'*A))*A'*dt(:);
u(i,j)=u(i,j)+M(1);
v(i,j)=v(i,j)+M(2);
end
end
end
end
end
result=zeros(size(u,1),size(u,2),3);
umax = 0;
vmax = 0;
umin = 10000;
vmin = 10000;
for i=1:size(u,1)
for j=1:size(u,2)
if (u(i,j)>umax)
umax = u(i,j);
end
if (u(i,j)<umin)
umin = u(i,j);
end
if (v(i,j)>vmax)
vmax = v(i,j);
end
if (v(i,j)<vmin)
vmin = v(i,j);
end
end
end
for i=1:size(u,1)
for j=1:size(u,2)
result(i,j,1) = 0.4;
result(i,j,2) = (u(i,j)-umin)/(umax-umin);
result(i,j,3) = (v(i,j)-vmin)/(vmax-vmin);
end
end
u = round(u);
v = round(v);
flag = zeros(size(u,1),size(u,2));
for i=1:1:size(u,1)
for j=1:1:size(u,2)
if (((i+v(i,j))>0)&&(i+v(i,j)<=size(u,1))&&(j+u(i,j)<=size(u,2))&&(j+u(i,j)>0))
result2(i+v(i,j),j+u(i,j),1) = im1(i,j,1);
result2(i+v(i,j),j+u(i,j),2) = im1(i,j,2);
result2(i+v(i,j),j+u(i,j),3) = im1(i,j,3);
flag(i,j) = 1;
else
continue;
end
end
end
for i=1:1:size(u,1)
for j=1:1:size(u,2)
if (flag(i,j)==0)
if (i==1)
result2(i,j)=im1(2,j);
elseif (i==size(u,1))
result2(i,j)=im1(i-1,j);
elseif (j==1)
result2(i,j)=im1(i,j+1);
elseif (j==size(u,2))
result2(i,j)=im1(i,j-1);
else
result2(i,j)=(im1(i-1,j)+im1(i,j-1)+im1(i+1,j)+im1(i,j+1))/4;
end
end
end
end
figure,imshow(result);
result = im2uint8(result);
B = smooth(result,10,4);
figure,imshow(B);
figure,imshow(result2);
kelotiya
- 粉丝: 4
- 资源: 9
最新资源
- Redis核心数据结构解析:字符串与列表的实现及应用场景
- PyTorch模型部署与服务化:模型导出优化、容器化、服务化架构及安全措施
- 基于储能的直驱风电机组并网仿真模型 直驱风电机组,先整流后逆变,不控整流器?pwm控制逆变器,出口电压380v,蓄电池储能经dcdc变器接入直流母线,可控制充放电,直流母线接有直流负载,可做加减负载突
- Go实战全家桶之三十三: go pprof定位问题,自己埋的坑
- Go实战全家桶之三十三: go pprof定位问题,自己埋的坑
- MATLAB代码:用于平抑可再生能源功率波动的储能电站建模及评价 关键词:储能电站 功率波动 并网 平抑可再生能源 参考文档:《用于平抑可再生能源功率波动的储能电站建模及评价》仅参考 光伏发电容量可
- STM32驱动lcd1602显示adc采集电压显示程序源码 主控芯片采用stm32f103,包括程序源码和protues仿真protues版本8.8. 需要做AD转的不要错过 程序源码注释详细,非
- 三相UPS不间断电源 从工频交流电开始,完成三相桥式整流电路、升压斩波电路及三相桥式PWM逆变电路的交-直-交变整个流程 类似于一个UPS对输入电源的变过程
- sTM32 ADC采集滤波算法,卡尔曼 中位值 同步对比输出源程序,芯片采用STM32f103c8t6.算法采用卡尔曼滤波算法中位值滤波算法, 波形输出正常采集的卡尔曼 中位值三个波形输出,程序注释详
- MMC并网逆变器(滑模控制) 1.MMC工作在整流侧,子模块个数N=22, 直流侧电压Udc=11kV,交流侧电压6.6kV 2.控制器采用双闭环控制,外环控制有功功率,采用PI调节器,电流内环采用无
- 2023-04-06-项目笔记 - 第三百七十二阶段 - 4.4.2.370全局变量的作用域-370 -2025.01.08
- 西门子界面官方精美触摸屏+WINCC程序模板 西门子官方触摸屏程序模板,炫酷的扁平式动画效果,脚本动画,自动生成二维码,可仿真,堪比智能手机,有精简,精致,wincc,无线面板等包含了所有西门子人机界
- 永磁同步电机的脉振高频注入仿真,可实现零速带满载启动,转速估算精度与角度估算精度非常高
- 双 向 绑 定~~~~~~~~~~~~~~~~~~~~~~~~
- bugreport-2025-01-08-220002.zip
- 高通量计算(Pandat代算或自己操作) 高通量计算筛选材料 实例6:在 Ni-xCr-yAl (x=10-100,y=10-100)成分空间中,合金的液相线、固相线、相含量的变化
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈