This repository has been archived by the owner. It is now read-only.
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?
CellSortPCAICA/functions/alternativePlot.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
188 lines (165 sloc)
7.29 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
function cell_sig_merged_array = alternativePlot(ica_segments, cluster, cell_sig, subPlotCols, sortedIdx, data_r, frames, fileNamesGreen, clusterSize, sweepDelay, sweepInterval, numberOfSweeps, sweepDuration,frameSteps) | |
f = figure; | |
plot1 = subplot(1,2,1); | |
plot2 = subplot(1,2,2); | |
drawEverything(1, subPlotCols, 1, size(cell_sig,2)); | |
for i=1:size(cluster, 2) | |
cell_sig_merged{i} = cell_sig(sortedIdx,:); | |
cell_sig_merged{i} = mean(cell_sig_merged{i}(cluster{i},:), 1); | |
end | |
%convert cell_sig_merged to array | |
cell_sig_merged_array = zeros(size(cell_sig_merged,2), size(cell_sig_merged{1},2)); | |
for i = 1:size(cell_sig_merged,2) | |
cell_sig_merged_array(i,:) = cell_sig_merged{i}; | |
end | |
%% add slider | |
%slider for selection of signals | |
imageSlider = uicontrol('Parent',f,'Style','slider',... | |
'value',0, 'min',0, 'max', ceil(size(cell_sig_merged,2)/clusterSize),... | |
'SliderStep', [1 1]/(ceil(size(cell_sig_merged,2)/clusterSize)),'Callback', @redrawPlot,... | |
'units','normalized','Position',[0.1 0.01 0.3 0.03]); | |
%slider for selection of x interval of right plot | |
plotSlider = uicontrol('Parent',f,'Style','slider',... | |
'value',0, 'min',0, 'max', ceil(size(cell_sig_merged{1},2)/frameSteps),... | |
'SliderStep', [1 1]/(ceil(size(cell_sig_merged{1},2)/frameSteps)),'Callback', @redrawPlot,... | |
'units','normalized','Position',[0.6 0.01 0.3 0.03]); | |
imagetxt = uicontrol('units','normalized','Style','text',... | |
'Position',[0.1 0.04 0.3 0.03],... | |
'String','Showing All ROIs'); | |
plottxt = uicontrol('units','normalized','Style','text',... | |
'Position',[0.6 0.04 0.3 0.03],... | |
'String','Showing All Frames'); | |
function redrawPlot(~,~) | |
val1 = round(imageSlider.Value); | |
val2 = round(plotSlider.Value); | |
%determine intervals for each value | |
if val1 == ceil(size(cell_sig_merged,2)/clusterSize) | |
iStart = (val1 - 1) * clusterSize + 1; | |
iEnd = subPlotCols; | |
else | |
iStart = (val1 - 1) * clusterSize + 1; | |
iEnd = clusterSize * val1; | |
end | |
if val1 == 0 | |
iStart = 1; | |
iEnd = subPlotCols; | |
end | |
if val2 == ceil(size(cell_sig_merged{1},2)/frameSteps) | |
kStart = (val2 - 1) * frameSteps + 1; | |
kEnd = size(cell_sig_merged{1},2); | |
else | |
kStart = (val2 - 1) * frameSteps + 1; | |
kEnd = frameSteps * val2; | |
end | |
if val2 == 0 | |
kStart = 1; | |
kEnd = size(cell_sig_merged{1},2); | |
end | |
imagetxt.String = ['Showing ROI ' num2str(iStart) ' to ' num2str(iEnd) ' of ' num2str(subPlotCols)]; | |
plottxt.String = ['Showing Frame ' num2str(kStart) ' to ' num2str(kEnd) ' of ' num2str(size(cell_sig_merged{1},2))]; | |
drawEverything(iStart, iEnd, kStart, kEnd); | |
end | |
function drawEverything(imageStart, imageEnd, plotStart, plotEnd) | |
cm = colormap(jet); | |
tempImage = zeros(size(ica_segments, 2), size(ica_segments, 3), 3); | |
for i = imageStart:imageEnd | |
rgb = cm(round(64/subPlotCols * (i-1)+1),:); | |
for k = cluster{i} | |
mask = squeeze(ica_segments(sortedIdx(k),:,:)); | |
%transform mask to only outlines | |
mask = imfill(mask, 'holes'); | |
mask = bwboundaries(mask); | |
mask = mask{:}; | |
%create image with drawn lines between points | |
linemask = zeros(size(ica_segments, 2), size(ica_segments, 3)); | |
for l = 1:size(mask,1) | |
linemask(mask(l,1),mask(l,2)) = 1; | |
end | |
for rgbIdx = 1:3 | |
tempImage(:,:,rgbIdx) = tempImage(:,:,rgbIdx) + rgb(rgbIdx)*linemask; | |
end | |
end | |
end | |
%set pixels 0 which are smaller than 0, seems to happen in rare cases.. | |
for i = 1:3 | |
tempImage(:,:,i) = (tempImage(:,:,i) > 0).*tempImage(:,:,i); | |
end | |
tempImage = uint16(tempImage*65535); | |
%calculate mean image | |
meanImage = mean(data_r,3); | |
maximum = max(meanImage(:)); | |
minimum = min(meanImage(:)); | |
meanImage = (meanImage - minimum)/(maximum-minimum); | |
meanImage = uint16(imadjust(meanImage, [0, 1], [0, 1], 0.4)*65535); | |
%set meanImage zero in every pixel which is not equal 0 in tempImage | |
meanImage = meanImage.*uint16(tempImage(:,:,1) == 0); | |
meanImage = meanImage.*uint16(tempImage(:,:,2) == 0); | |
meanImage = meanImage.*uint16(tempImage(:,:,3) == 0); | |
%copy meanImage in every colorchannel | |
for i = 1:3 | |
tempImage(:,:,i) = tempImage(:,:,i) + meanImage; | |
end | |
axes(plot1); | |
cla reset | |
imshow(tempImage); | |
%draw number in each roi | |
for i = imageStart:imageEnd | |
for drawNumberCt = cluster{i} | |
number = sortedIdx(drawNumberCt); %get position to draw number in | |
mask = squeeze(ica_segments(number,:,:)); | |
cog = centerofgravity(mask); | |
text(cog(2), cog(1), num2str(i), 'Color', 'white', 'FontSize', 15) | |
end | |
end | |
axes(plot2); | |
cla reset | |
hold on | |
cell_sigPlot = cell_sig(sortedIdx,:); | |
signal = zeros(size(cluster,2),size(cell_sig,2)); | |
for i = imageStart:imageEnd | |
for clusterIdx = cluster{i} | |
%subtract minimum value | |
minimum = min(cell_sigPlot(clusterIdx,:)); | |
cell_sigPlot(clusterIdx,:) = cell_sigPlot(clusterIdx,:) - minimum; | |
%norm cell signals | |
integral = median(cell_sigPlot(clusterIdx,:)); | |
cell_sigPlot(clusterIdx,:)=cell_sigPlot(clusterIdx,:)/abs(integral); | |
end | |
%mean value of all cluster signals | |
signal(i,:) = mean(cell_sigPlot(cluster{i},:), 1); | |
%add maximum position from signal from before | |
if i ~= 1 | |
%maximum = max(signal(i-1,:)); | |
maximum = max(max(cell_sigPlot(cluster{i-1},:))); | |
else | |
maximum = 0; | |
end | |
signal(i,:) = signal(i,:) + maximum; | |
rgb = cm(round(64/subPlotCols * (i-1)+1),:); | |
plot(signal(i,:), 'Color', rgb); | |
%text(size(signal,2), maximum, num2str(i)) | |
text(plotEnd, maximum, num2str(i)) | |
%plot single components dotted | |
for clusterIdx = cluster{i} | |
cell_sigPlot(clusterIdx,:) = cell_sigPlot(clusterIdx,:) + maximum; | |
plot(cell_sigPlot(clusterIdx, :),':', 'Color', rgb); | |
end | |
end | |
xlim([plotStart,plotEnd]); | |
%maximum = max(cell_sigPlot(:)); | |
ylim auto;%([0, maximum]); | |
%draw vertical lines | |
%ending of trials: | |
for i = 1:(size(frames,2)-1) | |
vline(frames(i), 'black', fileNamesGreen(i).name); | |
for s=1:numberOfSweeps | |
%draw begin of sweep | |
vline(frames(i)+sweepDelay+s*sweepInterval, 'b'); | |
%draw end of sweep | |
vline(frames(i)+sweepDelay+s*sweepInterval+sweepDuration, 'r'); | |
end | |
end | |
xlabel('Frames'); | |
ylabel('Intensity + Arbitrary Offset'); | |
end | |
end |