% This script runs an entire mosaicking and demosaicking process
% using the Li & Randhawa cubic-spline interpolation method.
%
% Written by Matt Golub for Psych 221, Winter Quarter, 2008.


clear all;
close all;

filename = 'frequency.png';
m_filt_width = 3;

[interpH, interpV] = LiRandhawa_Interp(filename);

Xcfa_NEG=bayerCFA_NEG(filename);
Xcfa=bayerCFA(filename);
X=double(imread(filename))/255;

omV = orientationMatrix(Xcfa);

omMed = medianFilt(omV,m_filt_width);

[output, mse, psnr] = LiRandhawa_DirectionSelectedOutput(interpH, interpV, omMed, double(~omMed), X, Xcfa_NEG);

%imwrite(output, [filename(1:end-4) 'CSI' num2str(m_filt_width) '.png'], 'png');
%save([filename(1:end-4) '-' num2str(m_filt_width)], 'interpH', 'interpV', 'Xcfa_NEG', 'Xcfa', 'X', 'omV', 'm_filt_width', 'omMed', 'output', 'mse', 'psnr');