public ImagePlus Kalmanizer(ImagePlus imp){
		int m = stack.getWidth();
		int n = stack.getHeight();
		//imp2 = new ImagePlus("Kalman Stack Filter", imp.getProcessor());/*original*/
		imp2 = new ImagePlus("Kalman Stack Filter", imp.getStack());/*7/25/03*/
		stack2 = imp2.createEmptyStack();
		int dimension = m*n;
		int stacksize = stack.getSize();
		short stackslice[] = new short[dimension];
		short filteredslice[] = new short[dimension];
		double noisevar[] = new double[dimension];
		double average[] = new double[dimension];
		double predicted[] = new double[dimension];
		double predictedvar[] = new double[dimension];
		double observed[] = new double[dimension];
		double Kalman[] = new double[dimension];
		double corrected[] = new double[dimension];
		double correctedvar[] = new double[dimension];
		
		for (int i=0;i<dimension;++i) noisevar[i] = percentvar;
		stackslice = (short[])stack.getPixels(1);
		predicted = short2double(stackslice);
		stack2.addSlice("1",double2short(predicted));
		predictedvar = noisevar;
		
		for(int i=1;i<stacksize;++i){
			stackslice = (short[])stack.getPixels(i+1);
			observed = short2double(stackslice);
			for(int k=0;k<Kalman.length;++k){
				Kalman[k] = predictedvar[k]/(predictedvar[k]+noisevar[k]);
			}
			for(int k=0;k<corrected.length;++k){
				corrected[k] = gain*predicted[k]+(1.0-gain)*observed[k]+Kalman[k]*(observed[k] - predicted[k]);
			}
			for(int k=0;k<correctedvar.length;++k){
				correctedvar[k] = predictedvar[k]*(1.0 - Kalman[k]);
			}
			predictedvar = correctedvar;
			predicted = corrected;
			filteredslice = double2short(corrected);
			ip2 = imp2.getProcessor();
			ip2.setPixels(filteredslice);
			stack2.addSlice(String.valueOf(i+1), ip2);
		}
		imp2.setStack("Kalman Stack Filter", stack2);
		return imp2;
	}