Skip to content
Permalink
master
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
folder = '\\storage.laur.corp.brain.mpg.de\Data_2\CoattiAlex\Experiments_2015\W66_20150212\RedShirtImaging\vsdtest_D';
filename = 'vsdtest_D002.tsm';
recording_file = strcat(folder,filesep,filename);
obj = redShirt(recording_file);
%% extract raw traces from subset of pixels
% ( 1 ) select pixels of ROIs (downsample image, reduce resolution) % % % % % % % % % % % % % % % % % % % % %
pix_linear_ind = reshape(1:256*256,256,256);
p_r = 8; p_c = 8; step_r = 1:p_r:256; step_c = 1:p_c:256;
roi_id = zeros(p_r * p_c * numel(step_r)*numel(step_c) ,1);
% pxl_id = reshape(1:length(index{1})*length(index{2}),length(index{1}),length(index{2})); %reshape(1:256*256,256,256);
pxl_id = pix_linear_ind;
counter = 0;
for c = step_c
for r = step_r
counter = counter + 1;
tempid = pxl_id(r: r + p_r-1, c: c + p_c-1);
roi_id((1:p_r*p_c) + p_r*p_c*(counter-1) ) = tempid(:);
end
end
% select the ROIs of the final downsampled image that you want to extract
% traces from
pix_downsample = reshape(1:length(step_r)*length(step_c),length(step_r),length(step_c));
roi_selected = [133,153,394,503,681,824];
% ( 2 ) INPUTs for getData method % % % % % % % % % % % % % % % % % % % % % %
channels = []; % choose single pixels of the full 256*256 matrix of linear indices (pxl_linear_ind)
% channels can either be a n*1 vector or a n*m matrix in the case of
% equally sized rois (to be implemented: allow for non-equally sized rois
% by ordering selected pixels in channels as a linear vector and in
% roi_size vector put the total number of pixels in each successive roi
% e.g. roi1 = 10 pxl, roi2 = 15 pxl, roi3 = 5 pxl etc roi_size = [10, 15, 3 ....]
for i = 1:length(roi_selected);
if i == 1
channels = roi_id( (roi_selected(i)-1) * p_r*p_c +[1:p_r*p_c] );
else
channels = [channels; roi_id( (roi_selected(i)-1) * p_r*p_c +[1:p_r*p_c] )];
end
end
events_time = 0; % frame number from which to start extracting data
startTime_ms = events_time .* (1/obj.samplingFrequency *1000); %starting frame * duration in ms of one frame
window_frames = 10000;
window_ms = repmat(window_frames * 1/obj.samplingFrequency *1000,1,length(startTime_ms)); % total number of frames in ms
mode = 'fullframe'; % mode 1 = 'fullframe' it extracts traces from all pixels of one frame
% mode 2 = 'single_pixels' it extracts traces for each pixels
% entered in the channels input and treats them separately
% mode 3 = 'roi' (an easy outline for ROIs could be
% rectangular and implement ROIs with any type of shape
% later)
name = [];
[raw_data, time_intervals] = obj.getData(channels,startTime_ms,window_ms,mode,name);
nTrials = length(startTime_ms);
raw_frames = reshape(raw_data,256,256,nTrials,max(window_frames));
[raw_pixels, time_intervals_pixels] = obj.getData(channels,startTime_ms,window_ms,mode,name);
% pixel order is subjected to two transformations by the algorithm for
% data extraction
% ind1 = NaN(1,256*256/2);
% ind2 = NaN(1,256*256/2);
% for c = 1:256
% ind1( [1:128]+128*(c-1) ) = [1:128] + 256*(c-1);
% ind2( [1:128]+128*(c-1) ) = fliplr([129:256] + 256*(c-1));
% end
% deinterleaving_matrix = cat(1,reshape(ind1,128,256),reshape(ind2,128,256));
% [~,ord] = sort(deinterleaving_matrix(channels));
% raw_temp = raw_pixels(ord,:,:);
% raw_pixels_in_frame = zeros( size(raw_temp) );
roi_mask = reshape(zeros(256*256,1),256,256);
roi_mask(channels) = 1;
% test to verify that the data read-in algorithm performs accurately
% (besides being more efficient)
figure,
subplot(121), imagesc(squeeze(squeeze(raw_frames(:,:,1,1))) .* roi_mask), axis square
subplot(122),
test_frame = reshape(zeros(256*256,1),256,256);
test_frame(channels) = raw_pixels(1:length(channels),1,1);
imagesc(test_frame), axis square