2016-12-01 94 views
-1

我想根据像素的强度(或颜色)适合线条到图像。下图显示了面板1中的典型测试图像,在面板2中绘制了一条线,手动。测试图像(矩阵)可以在此处下载:.RData from dropboxtest image (panel 1) with line drawn (panel 2)适合线条图像

我想用一个回归分析以产生类似于在面板2。然而所述手工画出的线条的东西,因为,与所有的图像,也有错误,我不能使用简单线性回归x轴和y轴。

我对相关方程,链接等的算法描述是开放的,不一定是我可以复制和粘贴的代码。

方法我想避免

  1. 3.3.3系列在与实际数据图像的各种斜坡绘制的像素的合成二进制图像。例如,下面两张图片的相关性会很好,但是我想避免这种方法。

enter image description here

  • 使用骨架算法来减小,使得简单的线性回归,可以使用该图像。
  • +0

    如果只有颜色可供选择,怎么样了平铺图像成相对较小的瓦片,并在每个瓦片中生成合成随机点,其数量/密度与瓦片的颜色相对应,然后在所得到的点上使用R的回归分析工具? –

    +0

    正交(全部)最小二乘可能是你想要的。见例如这里http://stackoverflow.com/questions/6872928/how-to-calculate-total-least-squares-in-r-orthogonal-regression – dww

    回答

    0

    地震学家,有趣的是,处理在那里他们校正基于一个地震源,并用称为正常搬出(Normal Moveout)的过程的接收器之间的距离反射数据类似的问题。我使用了类似的过程。

    的一般算法是:图像

    1. 负载限定一系列斜坡调查
    2. 定义窗口长度是<数量的图像列的
    3. 环在系列斜率和...
      • 定义在图像上的索引位置(x,y)基于图像的斜率和大小窗口(下图中第一行的灰色点)。
      • 从那些从上面的x,y位置索引的原始矩阵(下面图像的第二行中的图)建立矩阵。
      • 对该矩阵进行求和,然后通过除以总和矩阵的长度来将该和归一化。
      • 保存各总和(会有每速度你循环超过1个总和)
    4. 对应于最大(小)和向量的索引的速度矢量的最佳斜率/速度在当前像素列的图像(下图中的第三行)。
    5. 沿着图像的列执行上述步骤。

    该算法在下图中可视化描述。

    Algorithm description

    执行上述程序的代码是在这个问题给出的测试数据,一列是:

    load('test.RData') 
    
    ## INPUTS ## 
    img=test 
    
    vel.min=1 ## minimum velocity (or slope) to test 
    vel.max=20 ## max velocity to test 
    vel.number=100 ## how many velocities to test 
    win=10 ## size of window to investigate 
    
    ## define a time index 
    ti=nrow(img)/2 
    
    ## set up a vector to hold the velocity correlation values 
    vel.corrs <- rep(NA,vel.number) 
    
    ## define the set of velocities to search over 
    vels <- seq(vel.min,vel.max,length.out=vel.number) 
    
    ## define a velocity index 
    vi=1 
    
    while(vi<=length(vels)) { 
    
        ## build a binary matrix with corresponding to the window and velocity 
        bin.mat <- matrix(0,ncol=ncol(img),nrow=nrow(img)) 
        slope.line <- seq(0,ncol(bin.mat)/vels[vi],length.out=ncol(bin.mat)) 
        bin.mat[(ti-win/2):(ti+win/2),]=1 
    
    
        ## define the offeset 
        offset <- rep(slope.line,each=win+1) 
    
        ## define the indices of array points according to velocity and window 
        win.vel.ind <- cbind(which(bin.mat==1,arr.ind=TRUE)[,1]+offset,which(bin.mat==1,arr.ind=TRUE)[,2]) 
    
        ## limit the points to the dimensions of the image 
        if(any(floor(win.vel.ind[,1]) > nrow(img))){ 
         win.vel.ind[(which(floor(win.vel.ind[,1])>nrow(img))),]=NA 
         ##win.vel.ind <- win.vel.ind[-(which(floor(win.vel.ind[,1])>nrow(img))),] 
        } 
    
        ## pluck the values of the image associated with those non-NA indices 
        slice <- img[win.vel.ind] 
    
        ## build a matrix of the slice vector with nrow=win+1 
        slice.mat <- matrix(slice,nrow=win+1,ncol=ncol(img),byrow=FALSE) 
    
        ## apply a hamming window 
        ##ham.mat <- matrix(hamming(win+1),ncol=ncol(slice.mat),nrow=nrow(slice.mat)) 
        ##slice.ham <- slice.mat*ham.mat 
    
        ## sum this 'slice' and normalize and store 
        vel.corrs[vi] <- sum(slice,na.rm=TRUE)/length(na.omit(slice)) 
    
        vi=vi+1 
    }