Skip to content

Commit

Permalink
- Fixed issue where NaN were produced by JSpectralAnalysis if data to…
Browse files Browse the repository at this point in the history
… interpolate were outside bounds of InterpolationRebin object

- Added spectrum subtraction button to display the difference between two spectra
- Added auto generation of ROIs from each line in an 'image'. Useful for MS rather than MSI
  • Loading branch information
AlanRace committed Aug 17, 2017
1 parent 2783966 commit 41a83fe
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
15 changes: 14 additions & 1 deletion deploy.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,17 @@
% Ensure all folders are on the path
addpath(genpath(path));

mcc -v -m SpectralAnalysis.m -a lib/ -a src/ -a *.m
% Compile preprocessing methods
cd 'src/processing/preprocessing/'

mex -largeArrayDims rebin.c
mex -largeArrayDims synaptReplaceZeros.c

cd '../../../'

% Compile MEPCA methods
cd 'src/processing/postprocessing/mepca'
compileMEPCA
cd '../../../../'

mcc -v -m SpectralAnalysis.m -a lib/ -a src/ -a *.m -a *.mex*
Binary file modified lib/JSpectralAnalysis/JSpectralAnalysis.jar
Binary file not shown.
52 changes: 49 additions & 3 deletions src/gui/DataViewer.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
% Buttons for interacting with the spectrum list
addSpectrumButton;
overlaySpectrumButton;
subtractSpectrumButton;
removeSpectrumButton;

switchSpectrumViewButton;
Expand Down Expand Up @@ -788,18 +789,59 @@ function overlaySpectrumCallback(obj)
% axisHandle = axes;
multiSpectrumPanel = MultiSpectrumPanel(figure, obj.spectrumList.get(spectraToOverlay(1)));

warning('No preprocessing applied...');
spectraToOverlayList = [];

for i = 1:length(spectraToOverlay)
if(i == 1)
spectraToOverlayList = obj.spectrumList.get(spectraToOverlay(i));
else
spectraToOverlayList(i) = obj.spectrumList.get(spectraToOverlay(i));
end

if(~isempty(obj.preprocessingWorkflow))
spectraToOverlayList(i) = obj.preprocessingWorkflow.performWorkflow(spectraToOverlayList(i));
end
end

multiSpectrumDisplay = multiSpectrumPanel.spectrumDisplay;

for i = 2:length(spectraToOverlay)
multiSpectrumDisplay.setSpectrum(i, obj.spectrumList.get(spectraToOverlay(i)));
multiSpectrumDisplay.setSpectrum(i, spectraToOverlayList(i));
end

multiSpectrumDisplay.updateDisplay();
end
end

function subtractSpectrumCallback(this)
spectraToSubstract = this.spectrumListTableLastSelected(:, 1);

if(~isempty(spectraToSubstract) && length(spectraToSubstract) == 2)

spectrum1 = this.spectrumList.get(spectraToSubstract(1));
spectrum2 = this.spectrumList.get(spectraToSubstract(2));

if(~isempty(this.preprocessingWorkflow))
spectrum1 = this.preprocessingWorkflow.performWorkflow(spectrum1);
spectrum2 = this.preprocessingWorkflow.performWorkflow(spectrum2);
end

try
differenceSpectrum = SpectralData(spectrum1.spectralChannels, spectrum1.intensities - spectrum2.intensities);

figure = Figure();
figure.showStandardFigure();
spectrumPanel = SpectrumPanel(figure, differenceSpectrum);

figure.setTitle(['Difference between ' spectrum1.getDescription() ' and ' spectrum2.getDescription()]);
catch err
errordlg(err.message);
end
else
errordlg('Please select 2 spectra to subtract', 'DataViewer:NoSpectraSelected');
end
end

%% editPreprocessingWorkflow()
function editPreprocessingWorkflow(obj)
assignin('base', 'dataViewer', obj);
Expand Down Expand Up @@ -1101,6 +1143,9 @@ function createFigure(obj)
obj.overlaySpectrumButton = uicontrol('Parent', obj.spectrumListPanel, 'String', 'O', ...
'Callback', @(src, evnt) obj.overlaySpectrumCallback(), ...
'TooltipString', 'Overlay selected spectra');
obj.subtractSpectrumButton = uicontrol('Parent', obj.spectrumListPanel, 'String', 'S', ...
'Callback', @(src, evnt) obj.subtractSpectrumCallback(), ...
'TooltipString', 'Subtract selected spectra');
obj.removeSpectrumButton = uicontrol('Parent', obj.spectrumListPanel, 'String', '-', ...
'Callback', @(src, evnt) obj.removeSpectraFromListCallback(), ...
'TooltipString', 'Remove selected spectra from the list');
Expand Down Expand Up @@ -1291,7 +1336,8 @@ function sizeChanged(obj)

Figure.setObjectPositionInPixels(obj.addSpectrumButton, [margin, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.overlaySpectrumButton, [margin+panelPosition(3)/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.removeSpectrumButton, [margin+panelPosition(3)*2/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.subtractSpectrumButton, [margin+panelPosition(3)*2/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.removeSpectrumButton, [margin+panelPosition(3)*3/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
end

widthForSpectrum = widthForSpectrum - widthOfSpectrumList - margin;
Expand Down
21 changes: 21 additions & 0 deletions src/gui/RegionOfInterestListEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
editROIButton;
removeROIButton;

autoROIButton;

regionOfInterestEditor = 0;

roiFinishedEditingListener = 0;
Expand Down Expand Up @@ -70,6 +72,22 @@ function addRegionOfInterestCallback(this)
'FinishedEditing', @(src, evnt)this.finishedEditingRegionOfInterest(src.getRegionOfInterest()));
end

function autoRegionOfInterestCallback(this)
for i = 1:this.image.getHeight()
newROI = RegionOfInterest(this.image.getWidth(), this.image.getHeight());
newROI.setName(['Line ' num2str(i)]);

roi = zeros(this.image.getHeight(), this.image.getWidth());
roi(i, :) = 1;

newROI.addPixels(roi);

this.regionOfInterestList.add(newROI);

this.updateRegionOfInterestList();
end
end

function finishedEditingRegionOfInterest(this, regionOfInterest)
if(~isa(regionOfInterest, 'RegionOfInterest'))
exception = MException('RegionOfInterestListEditor:InvalidArgument', 'addRegionOfInterest: Must suply a RegionOfInterest.');
Expand Down Expand Up @@ -197,6 +215,9 @@ function createFigure(this)
'Units', 'normalized', 'Position', [0.6 0.125 0.1 0.05], 'Callback', @(src, evnt) this.editRegionOfInterest());
this.removeROIButton = uicontrol(this.handle, 'String', '-', ...
'Units', 'normalized', 'Position', [0.6 0.05 0.1 0.05], 'Callback', @(src, evnt) this.removeRegionOfInterestCallback());

this.autoROIButton = uicontrol(this.handle, 'String', 'Auto Line', ...
'Units', 'normalized', 'Position', [0.8 0.2 0.1 0.05], 'Callback', @(src, evnt) this.autoRegionOfInterestCallback());
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mex -largeArrayDims rebin.c
mex -largeArrayDims calculateE.c
mex -largeArrayDims updateQ.c

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
sChannels = obj.Parameters(1).value:obj.Parameters(3).value:obj.Parameters(2).value;

intensities = interp1(spectralChannels, intensities, sChannels);
intensities(isnan(intensities)) = 0;
spectralChannels = sChannels;
end
end
Expand Down

0 comments on commit 41a83fe

Please sign in to comment.