Skip to content

Commit e32099b

Browse files
committed
start the code of DW
1 parent bbf1173 commit e32099b

File tree

9 files changed

+327
-8
lines changed

9 files changed

+327
-8
lines changed

Demosaic/images/kodim19.png

656 KB
Loading

Demosaic/images/kodim19_8bits_RGGB.raw

Lines changed: 133 additions & 0 deletions
Large diffs are not rendered by default.

Demosaic/sketchMap.xlsx

-1.27 KB
Binary file not shown.

Demosaic/src/DW_GB2R.m

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
function [G,B] = DW_GB2R(neighborhoodData)
2+
% readRaw.m get rawData from HiRawImage
3+
% Input:
4+
% neighborhoodData the data of neighborhood range
5+
% Output:
6+
% [G B] The lack of G and B on R
7+
% Instructions:
8+
% author: wtzhu
9+
% e-mail: wtzhu_13@163.com
10+
% Last Modified by wtzhu v1.0 2022-01-22
11+
% Note:
12+
In = zeros(12, 1);
13+
Wn = zeros(12, 1);
14+
[h, w] = size(neighborhoodData);
15+
centerH = round(h/2);
16+
centerW = round(w/2);
17+
18+
In(1) = abs(neighborhoodData(centerH, centerW-1) - neighborhoodData(centerH, centerW+1)) + ...
19+
abs(neighborhoodData(centerH, centerW-2) - neighborhoodData(centerH, centerW));
20+
21+
In(2) = abs(neighborhoodData(centerH-1, centerW) - neighborhoodData(centerH+1, centerW)) + ...
22+
abs(neighborhoodData(centerH-2, centerW) - neighborhoodData(centerH, centerW));
23+
24+
In(3) = abs(neighborhoodData(centerH, centerW+1) - neighborhoodData(centerH, centerW-1)) + ...
25+
abs(neighborhoodData(centerH, centerW+2) - neighborhoodData(centerH, centerW));
26+
27+
In(4) = abs(neighborhoodData(centerH+1, centerW) - neighborhoodData(centerH-1, centerW)) + ...
28+
abs(neighborhoodData(centerH+2, centerW) - neighborhoodData(centerH, centerW));
29+
30+
In(5) = 0.5*(abs(neighborhoodData(centerH-1, centerW-2) - neighborhoodData(centerH+1, centerW+2)) + ...
31+
abs(neighborhoodData(centerH-2, centerW-4) - neighborhoodData(centerH, centerW)));
32+
33+
In(6) = 0.5*(abs(neighborhoodData(centerH-2, centerW-1) - neighborhoodData(centerH+2, centerW+1)) + ...
34+
abs(neighborhoodData(centerH-4, centerW-2) - neighborhoodData(centerH, centerW)));
35+
36+
In(7) = 0.5*(abs(neighborhoodData(centerH-2, centerW+1) - neighborhoodData(centerH+2, centerW-1)) + ...
37+
abs(neighborhoodData(centerH-4, centerW+2) - neighborhoodData(centerH, centerW)));
38+
39+
In(8) = 0.5*(abs(neighborhoodData(centerH-1, centerW+2) - neighborhoodData(centerH+2, centerW-1)) + ...
40+
abs(neighborhoodData(centerH-4, centerW+2) - neighborhoodData(centerH, centerW)));
41+
% -------------------------
42+
43+
In(9) = 0.5*(abs(neighborhoodData(centerH, centerW-1) - neighborhoodData(centerH, centerW+1)) + ...
44+
abs(neighborhoodData(centerH, centerW-2) - neighborhoodData(centerH, centerW)));
45+
46+
In(10) = 0.5*(abs(neighborhoodData(centerH, centerW-1) - neighborhoodData(centerH, centerW+1)) + ...
47+
abs(neighborhoodData(centerH, centerW-2) - neighborhoodData(centerH, centerW)));
48+
49+
In(11) = 0.5*(abs(neighborhoodData(centerH, centerW-1) - neighborhoodData(centerH, centerW+1)) + ...
50+
abs(neighborhoodData(centerH, centerW-2) - neighborhoodData(centerH, centerW)));
51+
52+
In(12) = 0.5*(abs(neighborhoodData(centerH, centerW-1) - neighborhoodData(centerH, centerW+1)) + ...
53+
abs(neighborhoodData(centerH, centerW-2) - neighborhoodData(centerH, centerW)));
54+
sumIn = 0;
55+
for i =1 :12
56+
sumIn = sumIn + (1/(1+In(i)));
57+
end
58+
for i =1 :12
59+
Wn(i) = (1/(1+In(i)))/sumIn;
60+
end
61+
G = 0;
62+
B = 0;

Demosaic/src/demosaic.m

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
%% --------------------------------
22
%% author:wtzhu
33
%% date: 20210705
4-
%% fuction: main file of Demosaic
4+
%% fuction: main file of Demosaic. The simple linear interpolation.
55
%% note: add RGGB format only, other formats will be added later
66
%% --------------------------------
77
clc;clear;close all;
88

9-
% ------------Raw Format----------------
10-
filePath = 'images/RGBTest_8bits_RGGB.raw';
9+
%% ------------Raw Format----------------
10+
filePath = 'images/kodim19_8bits_RGGB.raw';
1111
bayerFormat = 'RGGB';
12-
width = 640;
13-
height= 480;
12+
width = 512;
13+
height= 768;
1414
bits = 8;
15-
% --------------------------------------
15+
%% --------------------------------------
1616
bayerData = readRaw(filePath, bits, width, height);
1717
figure();
1818
imshow(bayerData);
1919
title('raw image');
2020

21-
% expand image inorder to make it easy to calculate edge pixels
21+
%% expand image inorder to make it easy to calculate edge pixels
2222
bayerPadding = zeros(height + 2,width+2);
2323
bayerPadding(2:height+1,2:width+1) = uint32(bayerData);
2424
bayerPadding(1,:) = bayerPadding(3,:);
2525
bayerPadding(height+2,:) = bayerPadding(height,:);
2626
bayerPadding(:,1) = bayerPadding(:,3);
2727
bayerPadding(:,width+2) = bayerPadding(:,width);
2828

29+
%% main code of imterpolation
2930
imDst = zeros(height+2, width+2, 3);
3031
for ver = 2:height + 1
3132
for hor = 2:width + 1
@@ -74,7 +75,7 @@
7475
imDst = uint8(imDst(2:height+1,2:width+1,:));
7576
figure,imshow(imDst);title('demosaic image');
7677

77-
orgImage = imread('images/RGBTest.jpg');
78+
orgImage = imread('images/kodim19.png');
7879
figure, imshow(orgImage);title('org image');
7980

8081

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
%% --------------------------------
2+
%% author:wtzhu
3+
%% date: 20220122
4+
%% fuction: The code of reference
5+
%% note:
6+
%% reference: "Directionally weighted color interpolation for digital cameras"
7+
%% --------------------------------
8+
clc;clear;close all;
9+
10+
%% ------------Raw Format----------------
11+
filePath = 'images/kodim19_8bits_RGGB.raw';
12+
bayerFormat = 'RGGB';
13+
width = 512;
14+
height= 768;
15+
bits = 8;
16+
%% --------------------------------------
17+
bayerData = readRaw(filePath, bits, width, height);
18+
figure();
19+
imshow(bayerData);
20+
title('raw image');
21+
22+
%% expand image inorder to make it easy to calculate edge pixels
23+
addpath('../publicFunction');
24+
bayerPadding = expandRaw(bayerData, 4);
25+
26+
%% main code of imterpolation
27+
imDst = zeros(height+8, width+8, 3);
28+
for ver = 5: height + 4
29+
for hor = 5: width +4
30+
fprintf('%d %d\n', ver, hor);
31+
% R channal
32+
if(1 == mod(ver, 2) && 1 == mod(hor, 2))
33+
disp('deal with R');
34+
neighborhoodData = bayerPadding(ver-4: ver+4, hor-4: hor+4);
35+
[G, B] = DW_GB2R(neighborhoodData);
36+
% B channal
37+
elseif (0 == mod(ver, 2) && 0 == mod(hor, 2))
38+
disp('deal with B')
39+
% Gr
40+
elseif (1 == mod(ver, 2) && 0 == mod(hor, 2))
41+
disp('deal with Gr')
42+
% Gb
43+
elseif (0 == mod(ver, 2) && 1 == mod(hor, 2))
44+
disp('deal with Gb')
45+
end
46+
47+
end
48+
end
49+
50+
51+

Demosaic/src/edgeBased.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
%% --------------------------------
2+
%% author:wtzhu
3+
%% date: 20220122
4+
%% fuction: The code of reference
5+
%% note:
6+
%% reference: "An Efficient Edge-Based Technique for Color Filter Array Demosaicking"
7+
%% --------------------------------
8+
clc;clear;close all;
9+
10+
%% ------------Raw Format----------------
11+
filePath = 'images/kodim19_8bits_RGGB.raw';
12+
bayerFormat = 'RGGB';
13+
width = 512;
14+
height= 768;
15+
bits = 8;
16+
%% --------------------------------------
17+
bayerData = readRaw(filePath, bits, width, height);
18+
figure();
19+
imshow(bayerData);
20+
title('raw image');
21+
22+
%% expand image inorder to make it easy to calculate edge pixels
23+
bayerPadding = zeros(height + 2,width+2);
24+
bayerPadding(2:height+1,2:width+1) = uint32(bayerData);
25+
bayerPadding(1,:) = bayerPadding(3,:);
26+
bayerPadding(height+2,:) = bayerPadding(height,:);
27+
bayerPadding(:,1) = bayerPadding(:,3);
28+
bayerPadding(:,width+2) = bayerPadding(:,width);
29+
30+
%% main code of imterpolation
31+
imDst = zeros(height+2, width+2, 3);
32+
33+

Demosaic/src/paddingImage.m

Whitespace-only changes.

publicFunction/readRaw.m

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function rawData = readRaw(fileName, bitsNum, width, height)
2+
% readRaw.m get rawData from HiRawImage
3+
% Input:
4+
% fileName the path of HiRawImage
5+
% bitsNum the number of bits of raw image
6+
% row the row of the raw image
7+
% col the column of the raw image
8+
% Output:
9+
% rawData the matrix of raw image data
10+
% Instructions:
11+
% author: wtzhu
12+
% e-mail: wtzhu_13@163.com
13+
% Last Modified by wtzhu v1.0 2021-06-29
14+
% Note:
15+
16+
% get fileID
17+
fin = fopen(fileName, 'r');
18+
% format precision
19+
switch bitsNum
20+
case 8
21+
disp('bits: 8');
22+
format = sprintf('uint8=>uint8');
23+
case 10
24+
disp('bits: 10');
25+
format = sprintf('uint16=>uint16');
26+
case 12
27+
disp('bits: 12');
28+
format = sprintf('uint16=>uint16');
29+
case 16
30+
disp('bits: 16');
31+
format = sprintf('uint16=>uint16');
32+
end
33+
I = fread(fin, width*height, format);
34+
% plot(I, '.');
35+
z = reshape(I, width, height);
36+
z = z';
37+
rawData = z;
38+
% imshow(z);
39+
end

0 commit comments

Comments
 (0)