All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.ojil.algorithm.StereoDynProg Maven / Gradle / Ivy

There is a newer version: 0.0.11
Show newest version
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *  
 *  You should have received a copy of the Lesser GNU General Public License
 *  along with this program.  If not, see .
 */

package com.github.ojil.algorithm;

/**
 * This is an implementation of stereo matching using dynamic programming.
 * Copyright 2008 by Jon A. Webb
 * @author webb
 */
public class StereoDynProg {
	private Integer[] rnRight, rnLeft;
    
    public StereoDynProg(Integer[] rnLeft, Integer[] rnRight) {
        this.rnLeft = rnLeft;
        this.rnRight = rnRight;
    }
    
    public Integer[] doMatch() {
        // first build an array matching every column of rnLeft with every
        // column of rnRight
        Integer[][] rnCost = new Integer[this.rnLeft.length][this.rnRight.length];
        for (int i=0; i=0) {
            rnDepth[nMatchRight] = nMatchLeft;
            // calculate the cost we should match
            int nCost = rnMin[nMatchLeft][nMatchRight] - 
                    rnCost[nMatchLeft][nMatchRight];
            // check if next node is to the left, up, or up and to the left
            if (nMatchRight>0 && nCost == rnMin[nMatchLeft][nMatchRight-1]) {
                    // nMatchLeft stays the same
                    nMatchRight--;
            } else if (nMatchLeft>0 && nCost == rnMin[nMatchLeft-1][nMatchRight]) {
                    // nMatchRight stays the same
                    nMatchLeft--;
            } else {
                // nMatchRight > 0, nMatchLeft > 0
                // nCost == rnMin[nMatchLeft-1][nMatchRight-1]
                nMatchRight--;
                nMatchLeft--;
            }
        }
        return rnDepth;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy