Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ColorRecon_OpEx19/QIS_color_ADMM.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
117 lines (90 sloc)
3.14 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%Authors : Abhiram Gnanasambandam (agnanasa@purdue.edu), | |
%Omar Elgendy (oelgendy@gigajot.tech),Stanley H. Chan (stanchan@purdue.edu) | |
%Intelligent Imaging Lab, Dept. of ECE, Purdue University | |
%References : | |
%[1] Megapixel photon-counting color imaging using quanta image sensor, | |
% Abhiram Gnanasambandam, Omar A. Elgendy, Jiaju Ma, and Stanley H. Chan, | |
% OSA Optics Express | |
%This code demonstrates the color reconstruction method described in the | |
%above mentioned paper. | |
clc,clear,close all | |
rng('default') | |
addpath('utils/denoisers') | |
addpath('ADMM_files') | |
addpath('Simulation/Matlab') | |
signalLevel = 2; | |
sigmaRN = 0.25; | |
%Number of frames | |
T = 1; | |
%Number of bits | |
Nbits = 5; | |
%% | |
% Will work only for the given setting | |
% May need to change these parameters if you are using this code for | |
% different settings. | |
lambdas = 0.02; | |
rhos = 0.8; | |
transposed = 0; | |
xGT = im2double(imread('data/lena.jpg')); | |
%xGT = imresize(xGT,[128,128]); | |
[H,W,~] = size(xGT); | |
if(H>W) | |
xGT = permute(xGT,[2,1,3]); | |
transposed = 1; | |
end | |
[H,W,~] = size(xGT); | |
H1=2^ceil(log2(H)); | |
W1=2^ceil(log2(W)); | |
xGT = imresize(xGT,[H1,W1]); | |
hr = [0 0;0 1]; | |
hg = [0 1;1 0]; | |
hb = [1 0;0 0]; | |
maskR = repmat(hr,H1/2,W1/2); | |
maskG = repmat(hg,H1/2,W1/2); | |
maskB = repmat(hb,H1/2,W1/2); | |
mask = cat(3,maskR,maskG,maskB); | |
[xL,xC1,xC2] = imsplit(RGB2LC1C2(xGT)); | |
xGT = LC1C22RGB(cat(3,xL,xC1,xC2)); | |
hr = repmat([0 0;0 1],H1/2,W1/2); | |
hg = repmat([0 1;1 0],H1/2,W1/2); | |
hb = repmat([1 0;0 0],H1/2,W1/2); | |
xCFA= sum(xGT.*cat(3,hr,hg,hb),3); | |
xGT255 = xGT*255.0; | |
peak = signalLevel/mean(xCFA(:)); | |
x = squeeze(sum(simulate_noisy_images_lite(xCFA*peak,sigmaRN,T,Nbits),1)); %poissrnd(xCFA*peak) + sigmaRN*randn(H1,W1); | |
%% | |
% Anscombe Transform for stabilizing the noise variance | |
% Would be generally appropriate to replace the Poisson VST with the | |
% corresponding VST for respective bet depth, which is outside the scope of | |
% this paper. | |
Z = 2*sqrt(max(3/8 + x + T*sigmaRN^2,0)); | |
ZRef = 2*sqrt(max(3/8 + x + T*sigmaRN^2,0)); | |
sigmaVST = 1; % Standard deviation after Anscombe Transform | |
ZWB = Z; | |
ZWBRef = ZRef; | |
sigmaWB = 1; | |
maxZ = max(ZWB(:)); | |
minZ = min(ZWB(:)); | |
Zn = (ZWB-minZ)/(maxZ-minZ); | |
sigmaNorm = sigmaWB/(maxZ-minZ); | |
% Reference Image | |
maxZRef = max(ZWBRef(:)); | |
minZRef = min(ZWBRef(:)); | |
ZnRef = (ZWBRef-minZRef)/(maxZRef-minZRef); | |
sigmaNormRef = sigmaWB/(maxZ-minZ); | |
x0 = double(demosaic(uint32((2^32-1)*Zn),'bggr'))/(2^32-1); | |
x0Ref = double(demosaic(uint32((2^32-1)*ZnRef),'bggr'))/(2^32-1); | |
denoiser = 'BM3D'; | |
lambda = lambdas; | |
rho = rhos; | |
gamma = 1; | |
max_itr = 10; | |
print = true; | |
Znhat = PlugPlayADMM_inpaint1(Zn.*mask,mask,lambda,denoiser,[],x0,rho,gamma,max_itr,print); | |
ZZ = Znhat*(maxZ-minZ) + minZ; | |
ZZ = ZZ.^2/4 - 3/8 - T*sigmaRN^2; | |
ZZ = ZZ/peak/T; | |
%% | |
figure; | |
subplot(1,2,1);imshow(x/T/(2^Nbits-1));title('Noisy input'); | |
subplot(1,2,2);imshow(ZZ); title('Color Reconstruction'); |