ccd camera exposure times get wrong randomly
4 views (last 30 days)
Show older comments
Hi,
I am using 4 ccd gige cameras with matlab code and have a problem for controlling the exposure times of ccd cameras.
I receive external trigger signal which does "pluse generator clear" and frame starts triggered by the pulse generator.
To get images under dark environment, exposure times are given by pulse width generated by camera's pulse generator.
I made usually 4 loops with different exposure times for exampe [1999 1000 500 200] (unit : ms). Pulse length has been set as 2300ms.
I found that some images' intensities are higher than given values. For example, a image whoes given exposure time is 500 has stronger intensity
than a image with 1999ms exposure time. It seems like some images' real exposure time is identical to pulse length.
I suspect that continuously generated pulse results in problems but i couldn't solve the problem yet.
The matlab code I have used is as follows:
clc; clear all; close all;
%//KAIST_Combustion_Lab_Flame_seed_Image_acquisition_with_software_trigger_G.J.Hwang
%% exposure time input
%bw1 = C2
%bw2 = CH
% prompt = {'Exposure_color (ms):','Exposure_UV (ms):'...
% ,'Exposure_BW1 (ms):','Exposure_BW2 (ms):'};
% title = 'Exposure time';
% dims = [1 35];
% definput = {'100','1000','1000','1000'};
% answer = inputdlg(prompt,title,dims,definput);
%% videoinput setting
v_bw1 = videoinput('gige',1,'Mono10'); %ch.1~4
v_uv = videoinput('gige',2,'Mono10');
v_color = videoinput('gige',4,'BayerRG8');
v_bw2 = videoinput('gige',3,'Mono10');
s1 = v_bw1.Source;
s2 = v_uv.Source;
s3 = v_color.Source;
s4 = v_bw2.Source;
%% camera setting
% Specify total number of frames to be acquired
% One frame is acquired for each external signal pulse.
%ex_time = [1500 750 400 200];
%ex_time = [200];
ex_time = [1000];
%ex_time = [1000 500 250 1999 1000];
%ex_time = [500 100 50];
s= size((ex_time),2);
fuel = 'CH4';
mode = 'BL';%'L_0.5_R_1.4_D_0.78_H_0.325_N2'; %'cond9'; %'BL';%
gain = 100;
num_shot = s;
for i=1:num_shot
numFrames = 1; % Enter the number of frame
% Color
s3.PulseGeneratorSelector = 'PulseGenerator1';
s3.PulseGeneratorClearActivation = 'RisingEdge';
s3.PulseGeneratorClearInverter = 'False';
s3.PulseGeneratorClearSource = 'PulseGenerator1';
%s3.PulseGeneratorClearSource = 'Line5';
s3.PulseGeneratorClock = 0.446428571428571;
%s3.PulseGeneratorFrequency = 0.500000080000013;
%s3.PulseGeneratorLengthMs = 1.1*str2num(answer{1});
s3.PulseGeneratorLengthMs = 2300;
s3.PulseGeneratorStartPoint = 1;
s3.PulseGeneratorEndPointMs = ex_time(i); % exposure time (ms)
ex_time(i)
color_et(i) =s3.PulseGeneratorEndPointMs
% UV
s2.PulseGeneratorSelector = 'PulseGenerator1';
s2.PulseGeneratorClearActivation = 'RisingEdge';
s2.PulseGeneratorClearInverter = 'False';
s2.PulseGeneratorClearSource = 'PulseGenerator1';
%s2.PulseGeneratorClearSource = 'Line5';
s2.PulseGeneratorClock = 0.446428571428571;
%s2.PulseGeneratorFrequency = 0.500000080000013;
% s2.PulseGeneratorLengthMs = 1.1*str2num(answer{2});
s2.PulseGeneratorLengthMs = 2300;
s2.PulseGeneratorStartPoint = 1;
s2.PulseGeneratorEndPointMs = ex_time(i); % exposure time (ms)
ex_time(i)
uv_et(i) =s2.PulseGeneratorEndPointMs
% BW1
s1.PulseGeneratorSelector = 'PulseGenerator1';
s1.PulseGeneratorClearActivation = 'RisingEdge';
s1.PulseGeneratorClearInverter = 'False';
s1.PulseGeneratorClearSource = 'PulseGenerator1';
%s1.PulseGeneratorClearSource = 'Line5';
s1.PulseGeneratorClock = 0.446428571428571;
%s1.PulseGeneratorFrequency = 0.500000080000013;
% s1.PulseGeneratorLengthMs = 1.1*str2num(answer{3});
s1.PulseGeneratorLengthMs = 2300;
s1.PulseGeneratorStartPoint = 1;
s1.PulseGeneratorEndPointMs = ex_time(i); % exposure time (ms)
ex_time(i)
bw1_et(i) =s1.PulseGeneratorEndPointMs
% BW2
s4.PulseGeneratorSelector = 'PulseGenerator1';
s4.PulseGeneratorClearActivation = 'RisingEdge';
s4.PulseGeneratorClearInverter = 'False';
s4.PulseGeneratorClearSource = 'PulseGenerator1';
%s4.PulseGeneratorClearSource = 'Line5';
s4.PulseGeneratorClock = 0.446428571428571;
%s4.PulseGeneratorFrequency = 0.500000080000013;
% s4.PulseGeneratorLengthMs = 1.1*str2num(answer{4});
s4.PulseGeneratorLengthMs = 2300;
s4.PulseGeneratorStartPoint = 1;
s4.PulseGeneratorEndPointMs = ex_time(i); % exposure time (ms)
ex_time(i)
bw2_et(i) =s4.PulseGeneratorEndPointMs
% v_bw1.LoggingMode = 'disk';
% v_uv.LoggingMode = 'disk';
% v_color.LoggingMode = 'disk';
% v_bw2LoggingMode = 'disk';
v_bw1.FramesPerTrigger = 1;
v_uv.FramesPerTrigger = 1;
v_color.FramesPerTrigger = 1;
v_bw2.FramesPerTrigger = 1;
v_bw1.TriggerRepeat = 0;
v_uv.TriggerRepeat = 0;
v_color.TriggerRepeat = 0;
v_bw2.TriggerRepeat = 0;
% Specify 'hardware' videoinput trigger type
% triggerconfig(v_bw1, 'manual');
% triggerconfig(v_uv, 'manual');
% triggerconfig(v_color, 'manual');
% triggerconfig(v_bw2, 'manual');
triggerconfig(v_bw1, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_uv, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_color, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
triggerconfig(v_bw2, 'hardware', 'DeviceSpecific', 'DeviceSpecific');
s1.TriggerSelector = 'FrameStart';
s2.TriggerSelector = 'FrameStart';
s3.TriggerSelector = 'FrameStart';
s4.TriggerSelector = 'FrameStart';
s1.TriggerSource = 'PulseGenerator1';
s2.TriggerSource = 'PulseGenerator1';
s3.TriggerSource = 'PulseGenerator1';
s4.TriggerSource = 'PulseGenerator1';
% s1.TriggerSource = 'Line5';
% s2.TriggerSource = 'Line5';
% s3.TriggerSource = 'Line5';
% s4.TriggerSource = 'Line5';
s1.TriggerActivation = 'RisingEdge';
s2.TriggerActivation = 'RisingEdge';
s3.TriggerActivation = 'RisingEdge';
s4.TriggerActivation = 'RisingEdge';
s1.TriggerMode = 'on';
s2.TriggerMode = 'on';
s3.TriggerMode = 'on';
s4.TriggerMode = 'on';
s1.GainRaw = gain;
s2.GainRaw = gain;
s3.GainRaw = gain;
s4.GainRaw = gain;
% For exposure time control configure a TriggerWidth exposure mode
s1.ExposureMode = 'TriggerWidth';
s2.ExposureMode = 'TriggerWidth';
s3.ExposureMode = 'TriggerWidth';
s4.ExposureMode = 'TriggerWidth';
%answer1 = questdlg('Take a shot?','Take a shot','Shot','No','Shot');% Start hardware-triggered buffered continuous acquisition, and wait for
% acquisition to complete
%% acquisition of image
'push'
start([v_bw1 v_uv v_color v_bw2])
wait([v_bw1 v_uv v_color v_bw2], 10)
% wait(v_uv, 5)
% wait(v_bw1, 5)
% wait(v_bw2, 5)
% Eventlog
%% Event log
elog_color = v_color.EventLog;
elog_uv = v_uv.EventLog;
elog_bw1 = v_bw1.EventLog;
elog_bw2 = v_bw2.EventLog;
%% Data log
elog_bw1(1).Data
elog_uv(1).Data
elog_color(1).Data
elog_bw2(1).Data
elog_bw1(2).Data
elog_uv(2).Data
elog_color(2).Data
elog_bw2(2).Data
%
% fn_color=mat2str(elog_color(2).Data.AbsTime);
% fn_uv=mat2str(elog_uv(2).Data.AbsTime);
% fn_bw1=mat2str(elog_bw1(2).Data.AbsTime);
% fn_bw2=mat2str(elog_bw2(2).Data.AbsTime);
fn_color=mat2str(s3.GainRaw);
fn_uv=mat2str(s2.GainRaw);
fn_bw1=mat2str(s1.GainRaw);
fn_bw2=mat2str(s4.GainRaw);
%% Transfer acquired frames and timestamps from acquisition input buffer
% into workspace
data_color = getdata(v_color, v_color.FramesAvailable);
data_uv = getdata(v_uv, v_uv.FramesAvailable);
data_bw1 = getdata(v_bw1, v_bw1.FramesAvailable);
data_bw2 = getdata(v_bw2, v_bw2.FramesAvailable);
vid_bw1Image=imrotate(data_bw1,-90); % image processing
vid_bw2Image=imrotate(data_bw2,90);
vid_colorImage=imrotate(data_color,-90);
vid_uvImage=imrotate(data_uv,90);
vid_colorImage = imadjust(vid_colorImage,[0 0 0;0.706 1 0.706],[]);
% vid_colorImage=demosaic(vid_colorImage, 'grbg');
DIRNAME1 = datestr(now,'yyyymmdd'); % create folders
DIRNAME2 = mode;
DIRNAME3 = num2str(ex_time(i));
pathname1 = ['C:\Users\admin\Documents\gyujin\code','\',DIRNAME1,'\',DIRNAME2,'\',DIRNAME3,'\'];
pathname2 = ['C:\Users\admin\Documents\gyujin\code','\',DIRNAME1,'\',DIRNAME2,'\',DIRNAME3,'\','original','\'];
mkdir(pathname1);
mkdir(pathname2);
% imwrite(vid_bw1Image,[pathname1,'bw1','.jpg']); % save images
% imwrite(vid_bw2Image,[pathname1,'bw2','.jpg']);
% imwrite(vid_uvImage,[pathname1,'uv','.jpg']);
% imwrite(vid_colorImage,[pathname1,'color','.jpg']);
%
% imwrite(vid_bw1Image,[pathname2,'bw1_C2_t=', answer{3}, '_', 'g=', fn_bw1,'.jpg']); % save images
% imwrite(vid_bw2Image,[pathname2,'bw2_CH_t=', answer{4}, '_', 'g=', fn_bw2, '.jpg']);
% imwrite(vid_uvImage,[pathname2,'uv_t=', answer{2}, '_', 'g=', fn_uv,'.jpg']);
% imwrite(vid_colorImage,[pathname2,'color_t=', answer{1}, '_', 'g=', fn_color,'.jpg']);
%% Image write to file
imwrite(vid_bw1Image,[pathname1,'bw1','.png']); % save images
imwrite(vid_bw2Image,[pathname1,'bw2','.png']);
imwrite(vid_uvImage,[pathname1,'uv','.png']);
imwrite(vid_colorImage,[pathname1,'color','.png']);
imwrite(vid_bw1Image,[pathname2,'bw1_C2_t=', num2str(ex_time(i)), '_', 'g=', fn_bw1,'.png']); % save images
imwrite(vid_bw2Image,[pathname2,'bw2_CH_t=', num2str(ex_time(i)), '_', 'g=', fn_bw2, '.png']);
imwrite(vid_uvImage,[pathname2,'uv_t=', num2str(ex_time(i)), '_', 'g=', fn_uv,'.png']);
imwrite(vid_colorImage,[pathname2,'color_t=', num2str(ex_time(i)), '_', 'g=', fn_color,'.png']);
figure();
subplot(2,2,3);
imshow(uint8(vid_bw1Image));
subplot(2,2,4);
imshow(uint8(vid_bw2Image));
subplot(2,2,1);
imshow((vid_colorImage));
subplot(2,2,2);
imshow(uint8(vid_uvImage));
v_color.framesavailable
flushdata(v_bw1, 'all');
flushdata(v_uv, 'all');
flushdata(v_bw2, 'all');
flushdata(v_color, 'all');
end
delete(v_color);
delete(v_uv);
delete(v_bw1);
delete(v_bw2);
clear v_color;
clear v_uv;
clear v_bw1;
clear v_bw2;
0 Comments
Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!