2011-05-25 17:21

非刚性图像配准 matlab简单示例 demons算法,

% Clean clc; clear all; close all;

% Compile the mex files %compile_c_files

% Read two images I1=im2double(imread('ssftrinew1.png')); 
I2=im2double(imread('ssftri.png'));

% Set static and moving image S=I2; M=I1;

% Alpha (noise) constant alpha=2.5;

% Velocity field smoothing kernel Hsmooth=fspecial('gaussian',[60 60],10);

% The transformation fields Tx=zeros(size(M)); Ty=zeros(size(M)); Tz=zeros(size(M));

[Sy,Sx] = gradient(S); for itt=1:200      % Difference image between moving and static image         Idiff=M-S;

% Default demon force, (Thirion 1998)         %Ux = -(Idiff.*Sx)./((Sx.^2+Sy.^2)+Idiff.^2);         %Uy = -(Idiff.*Sy)./((Sx.^2+Sy.^2)+Idiff.^2);

% Extended demon force. With forces from the gradients from both         % moving as static image. (Cachier 1999, He Wang 2005)         [My,Mx] = gradient(M);         Ux = -Idiff.*  ((Sx./((Sx.^2+Sy.^2)+alpha^2*Idiff.^2))+(Mx./((Mx.^2+My.^2)+alpha^2*Idiff.^2)));        
Uy = -Idiff.* 
((Sy./((Sx.^2+Sy.^2)+alpha^2*Idiff.^2))+(My./((Mx.^2+My.^2)+alpha^2*Idiff.^2)));           % When divided by zero         Ux(isnan(Ux))=0; Uy(isnan(Uy))=0;

% Smooth the transformation field         Uxs=3*imfilter(Ux,Hsmooth);         Uys=3*imfilter(Uy,Hsmooth);

% Add the new transformation field to the total transformation field.         Tx=Tx+Uxs;         Ty=Ty+Uys;         %M=movepixels(I1,Tx,Ty,Tz,0);         M=movepixels_2d_double(I1,Tx,Ty,0); end gridelment=gridshow(); gridelment=movepixels_2d_double(im2double(gridelment),Tx,Ty,0); subplot(1,3,1), imshow(I1,[]); title('image 1'); subplot(1,3,2), imshow(I2,[]); title('image 2'); subplot(1,3,3), imshow(M,[]); title('Registered image 1'); figure,subplot(131),imshow(I1),subplot(132),imshow(abs(I2-M)),subplot(133),imshow(abs(I2-I1)) figure,imshow(gridelment)

function gridelment=gridshow() gridelment=ones(256,256)*255; for i=1:5:256     gridelment(i,:)=0;     end for j=1:5:256         gridelment(:,j)=0; end gridelment=uint8(gridelment); imshow(gridelment);

function Iout=movepixels_2d_double(Iin,Tx,Ty,mode) % This function movepixels, will translate the pixels of an image %  according to x and y translation images (bilinear interpolated). % %  Iout = movepixels_2d_double(I,Tx,Ty,mode); % % Inputs; %   Tx, Ty: The transformation images, describing the %             (backwards) translation of every pixel in x and y direction. %   mode: If 0: linear interpolation and outside pixels set to nearest pixel %            1: linear interpolation and outside pixels set to zero %            (cubic interpolation only supported by compiled mex file) %            2: cubic interpolation and outsite pixels set to nearest pixel %            3: cubic interpolation and outside pixels set to zero % % Outputs, %   Iout : The transformed image % % Function is written by D.Kroon University of Twente (February 2009)   % Make all x,y indices [x,y]=ndgrid(0:size(Iin,1)-1,0:size(Iin,2)-1);

% Calculate the Transformed coordinates Tlocalx = x+Tx; Tlocaly = y+Ty;

% All the neighborh pixels involved in linear interpolation. xBas0=floor(Tlocalx);
yBas0=floor(Tlocaly); xBas1=xBas0+1;           yBas1=yBas0+1;

% Linear interpolation constants (percentages) xCom=Tlocalx-xBas0;
yCom=Tlocaly-yBas0; perc0=(1-xCom).*(1-yCom); perc1=(1-xCom).*yCom; perc2=xCom.*(1-yCom); perc3=xCom.*yCom;

% limit indexes to boundaries check_xBas0=(xBas0<0)|(xBas0>(size(Iin,1)-1)); check_yBas0=(yBas0<0)|(yBas0>(size(Iin,2)-1)); xBas0(check_xBas0)=0;
yBas0(check_yBas0)=0;
check_xBas1=(xBas1<0)|(xBas1>(size(Iin,1)-1)); check_yBas1=(yBas1<0)|(yBas1>(size(Iin,2)-1)); xBas1(check_xBas1)=0;
yBas1(check_yBas1)=0;

Iout=zeros(size(Iin)); for i=1:size(Iin,3);        Iin_one=Iin(:,:,i);     % Get the intensities     intensity_xyz0=Iin_one(1+xBas0+yBas0*size(Iin,1));     intensity_xyz1=Iin_one(1+xBas0+yBas1*size(Iin,1));     intensity_xyz2=Iin_one(1+xBas1+yBas0*size(Iin,1));     intensity_xyz3=Iin_one(1+xBas1+yBas1*size(Iin,1));     % Make pixels before outside Ibuffer mode     if(mode==1||mode==3)         intensity_xyz0(check_xBas0|check_yBas0)=0;         intensity_xyz1(check_xBas0|check_yBas1)=0;         intensity_xyz2(check_xBas1|check_yBas0)=0;         intensity_xyz3(check_xBas1|check_yBas1)=0;     end     Iout_one=intensity_xyz0.*perc0+intensity_xyz1.*perc1+intensity_xyz2.*perc2+intensity_xyz3.*perc3;     Iout(:,:,i)=reshape(Iout_one, [size(Iin,1) size(Iin,2)]); end

非刚性图像配准 matlab简单示例 demons算法的更多相关文章

  1. QT创建模态对话框阻塞整个应用程序和非模态对话框唯一性约束的简单示例

    QT创建模态对话框阻塞整个应用程序和非模态对话框唯一性约束的简单示例 部分代码: // 创建模态对话框阻塞整个应用程序和非模态对话框唯一性约束 QMenu *pDialog = mBar->ad ...

  2. 【计算机视觉】图像配准(Image Registration)

    (Source:https://blog.sicara.com/image-registration-sift-deep-learning-3c794d794b7a)  图像配准方法概述 图像配准广泛 ...

  3. 图像配准:从SIFT到深度学习

      图像配准(Image Registration)是计算机视觉中的基本步骤.在本文中,我们首先介绍基于OpenCV的方法,然后介绍深度学习的方法. 什么是图像配准 图像配准就是找到一幅图像像素到另一 ...

  4. CV 两幅图像配准

    http://www.cnblogs.com/Lemon-Li/p/3504717.html 图像配准算法一般可分为: 一.基于图像灰度统计特性配准算法:二.基于图像特征配准算法:三.基于图像理解的配 ...

  5. PCA检测人脸的简单示例_matlab实现

    PCA检测人脸的简单示例,matlab R2009b上实现训练:训练用的20副人脸: %训练%Lx=X'*Xclear;clc;train_path='..\Data\TrainingSet\';ph ...

  6. 【图像配准】基于互信息的图像配准算法:MI、EMI、ECC算法

    简单介绍: 基于互信息的图像配准算法以其较高的配准精度和广泛的适用性而成为图像配准领域研究的热点之中的一个.而基于互信息的医学图像配准方法被觉得是最好的配准方法之中的一个.基于此.本文将介绍简单的基于 ...

  7. 【Canvas】(1)---概述+简单示例

    Canvas---概述+简单示例 如果通俗的去理解Canvas,我们可以去理解成它类似于我们电脑自带的画图工具一样,canvas首先是选择一块画布,然后在这个画布上描绘我们想画的东西,画好后展示给用户 ...

  8. 【图像配准】基于灰度的模板匹配算法(一):MAD、SAD、SSD、MSD、NCC、SSDA、SATD算法

    简介: 本文主要介绍几种基于灰度的图像匹配算法:平均绝对差算法(MAD).绝对误差和算法(SAD).误差平方和算法(SSD).平均误差平方和算法(MSD).归一化积相关算法(NCC).序贯相似性检测算 ...

  9. Opencv探索之路(二十):制作一个简易手动图像配准工具

    近日在做基于sift特征点的图像配准时遇到匹配失败的情况,失败的原因在于两幅图像分辨率相差有点大,而且这两幅图是不同时间段的同一场景的图片,所以基于sift点的匹配已经找不到匹配点了.然后老师叫我尝试 ...

随机推荐

  1. csuoj 1355: 地雷清除计划

    这是一个非常神奇的题: 感觉像一个模拟搜索: 但是竟然可以用网络流来解决: 直接粘题解把: 如果不能走通的话,必然说明能够从右上角(图外面)沿雷“跳” ,一直可以“跳”左下角(图外面) ,因此建好图之 ...

  2. 1182-IP地址转换

    描述 给定一个点分十进制的IP地址,把这个IP地址转换为二进制形式. 输入 输入只有一行,一个点分十进制的IP地址 包括四个正整数,用三个.分开,形式为a.b.c.d 其中0<=a,b,c,d& ...

  3. android ExpandableListActivity的使用

    package com.example.keKuoZhanLieBiao; import android.app.ExpandableListActivity; import android.os.B ...

  4. IDEA 整合Junit实现自动生成测试代码

    1.安装插件 junit generator 重启IDEA,完成安装. 2. 选中需要测试的方法,按alt + insert 即可自动生成测试类\方法 3. 设置

  5. bulkTransfer通讯必须注意的问题:bulk buffer size(16K)

    Android USB host与HID使用bulkTransfer通讯接收和发送的数据长度不会超过16384,这个问题困扰了我很长一段时间,终于发现问题所在,不是出在我的程序设计,也不是硬件的发送/ ...

  6. Android 关于HttpClient上传中文乱码的解决办法

    使用过HttpClient的人都知道可以通过addTextBody方法来添加要上传的文本信息,但是,如果要上传中文的话,或还有中文名称的文件会出现乱码的问题,解决办法其实很简单: 第一步:设置Mult ...

  7. scaleform mobile sdk for android 多点触摸 修正

    修正 scaleform 的多点触控 (随手一记 给后来的人做个参考) scaleform 版本号 4.2.24 (估计这就是最后一个 移动版的版本了,万年没有更新了) 开始 一直以为 scalefo ...

  8. Hadoop中两表JOIN的处理方法

    Dong的这篇博客我觉得把原理写的很详细,同时介绍了一些优化办法,利用二次排序或者布隆过滤器,但在之前实践中我并没有在join中用二者来优化,因为我不是作join优化的,而是做单纯的倾斜处理,做joi ...

  9. Luogu_1565_牛宫_(最大子矩阵)

    描述 http://www.luogu.org/problem/show?pid=1565 给出一个n*m的矩阵,求最大的且和值为正的子矩阵. 分析 很容易想到的是用前缀和维护,暴力枚举左上角和右下角 ...

  10. Linux Kernel ‘oz_cdev_write()’函数本地缓冲区溢出漏洞

    漏洞名称: Linux Kernel ‘oz_cdev_write()’函数本地缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-060 发布时间: 2013-11-07 更新时间: 201 ...