Skip to content

Commit

Permalink
Merge branch 'CA6.0beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
yuminguw committed Mar 22, 2024
2 parents b45d68c + 8be4ecf commit 27a07e5
Show file tree
Hide file tree
Showing 39 changed files with 3,412 additions and 511 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
1,138 changes: 911 additions & 227 deletions src/CurveAlign_CT-FIRE/Cellanalysis/CellAnalysisForCurveAlign_exported.m

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/CurveAlign_CT-FIRE/Cellanalysis/StarDistPrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def prediction(images, index):
labels, details = model.predict_instances(img, prob_thresh=0.2, nms_thresh=0.5)

im = Image.fromarray(labels)
im.save('mask.tif')
im.save('mask_sd.tif')

sio.savemat('labels.mat', {'labels':labels})
sio.savemat('details.mat', {'details':details})
sio.savemat('labels_sd.mat', {'labels':labels})
sio.savemat('details_sd.mat', {'details':details})

return labels, details
Binary file not shown.
146 changes: 131 additions & 15 deletions src/CurveAlign_CT-FIRE/Cellanalysis/TumorRegionAnnotationGUI_exported.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
properties (Access = public)
TumorRegionDetectionoptionsUIFigure matlab.ui.Figure
SliderDensityParameter matlab.ui.control.Slider
SliderGrideRow matlab.ui.control.Slider
SliderGridRow matlab.ui.control.Slider
SliderGridCol matlab.ui.control.Slider
GridRowsEditField matlab.ui.control.NumericEditField
GridRowsEditFieldLabel matlab.ui.control.Label
Expand Down Expand Up @@ -39,8 +39,8 @@
% Code that executes after component creation
function startupFcn(app, mainApp)
app.CallingApp = mainApp;
app.parameterOptions.imagePath = pwd;%mainApp.CAPannotations.imagePath;
app.parameterOptions.imageName = mainApp.CAPannotations.imageName;
app.parameterOptions.imagePath = mainApp.imagePath;
app.parameterOptions.imageName = mainApp.imageName;
app.PathtoimageEditField.Value = fullfile(app.parameterOptions.imagePath,...
app.parameterOptions.imageName);

Expand All @@ -59,8 +59,118 @@ function CancelButtonPushed(app, event)

% Button pushed function: OKButton
function OKButtonPushed(app, event)
% parameterOptions = struct('imagePath','','imageName','','imageType','HE bright field',...
% 'method','ranking', 'gridColumn', 50,'gridRow', 50,'parameter_threshold',5,...
% 'defaultParameters',1,'sendtoROImanager',1);
if ~strcmp(app.parameterOptions.imageType,'HE bright field')
disp('Only available for HE bright field images so far')
return
end
% parameterOptions = struct('imagePath','','imageName','','imageType','HE bright field',...
% 'method','ranking', 'gridColumn', 50,'gridRow', 50,'parameter_threshold',5,...
% 'defaultParameters',1,'sendtoROImanager',1);
gridCols = app.parameterOptions.gridColumn;
gridRows = app.parameterOptions.gridRow;
thresholdP = app.parameterOptions.parameter_threshold;
% three options
% 1-Ranking
% 2-Area threshold (in Pixels)
% 3-Distance Based
if strcmp(app.AnnotationMethodsDropDown.Value,'Ranking')
% thresholdValue = app.ParametersEditField.Value;
turmorDetected = imageCardTumor(app.CallingApp.imageName,'Rank',...
[gridCols gridRows],thresholdP);
elseif strcmp(app.AnnotationMethodsDropDown.Value,'Area threshold (in Pixels)')
% thresholdValue = app.ParametersEditField.Value;
turmorDetected = imageCardTumor(app.CallingApp.imageName,'Thres',...
[gridCols gridRows],thresholdP);
elseif strcmp(app.AnnotationMethodsDropDown.Value,'Distance Based')
% thresholdValue = app.ParametersEditField.Value;
turmorDetected = imageCardTumor(app.CallingApp.imageName,'Radius',...
[gridCols gridRows],nan,thresholdP);
else
fprintf('This tumor annotation method-%s is not available \ n',app.AnnotationMethodsDropDown.Value)
return
end
% add more annotation properties in the main program
app.CallingApp.CAPannotations.tumorAnnotations.tumorArray = turmorDetected.tumorArray;
annotationNumber = size (app.CallingApp.CAPannotations.tumorAnnotations.tumorArray,2);
% statsArray = cell(1,annotationNumber); % struct('Mask','','Centroid','','Area','','Perimeter','')
% nrow = app.CallingApp.CAPimage.imageInfo.Height;
% ncol = app.CallingApp.CAPimage.imageInfo.Width;
% for i = 1: annotationNumber
% tumorData = app.CallingApp.CAPannotations.tumorAnnotations.tumorArray(1,i);
% tumorBoundaryCol = tumorData.boundary(:,2);
% tumorBoundaryRow = tumorData.boundary(:,1);
% tumorMask = poly2mask(tumorBoundaryCol,tumorBoundaryRow,nrow,ncol);
% stats = regionprops(tumorMask,'Centroid','Area','Perimeter','Orientation');
% statsArray{1,i}.Mask = tumorMask;
% statsArray{1,i}.Centroid = stats.Centroid;
% statsArray{1,i}.Area = stats.Area;
% statsArray{1,i}.Perimeter = stats.Perimeter;
% statsArray{1,i}.Orientation = stats.Orientation;
% end
% app.CallingApp.CAPannotations.tumorAnnotations.statsArray = statsArray;
app.CallingApp.annotationView.Type = repmat({'tumor'},annotationNumber,1);
app.CallingApp.annotationType = 'tumor';
app.CallingApp.figureOptions.plotImage =0;
app.CallingApp.figureOptions.plotObjects =0;
app.CallingApp.figureOptions.plotAnnotations = 1;
% delete fibers if exist
if ~isempty (app.CallingApp.fibersView.fiberH1)
fiberNumber = size(app.CallingApp.fibersView.fiberH1,1);
for i= 1: fiberNumber
delete(app.CallingApp.fibersView.fiberH1{i,1});
end
end
app.CallingApp.plotImage_public;
app.CallingApp.TabGroup.SelectedTab = app.CallingApp.ROImanagerTab;

end

% Value changed function: SliderDensityParameter
function SliderDensityParameterValueChanged(app, event)
value = app.SliderDensityParameter.Value;
app.SliderDensityParameter.Value = round(value);
app.parameterOptions.parameter_threshold = app.SliderDensityParameter.Value;
app.ParametersEditField.Value = app.SliderDensityParameter.Value;
end

% Value changed function: SliderGridCol
function SliderGridColValueChanged(app, event)
value = app.SliderGridCol.Value;
app.SliderGridCol.Value = round(value);
app.parameterOptions.gridColumn = app.SliderGridCol.Value;
app.GridColumnsEditField.Value = app.SliderGridCol.Value;
end

% Value changed function: SliderGridRow
function SliderGridRowValueChanged(app, event)
value = app.SliderGridRow.Value;
app.SliderGridRow.Value = round(value);
app.parameterOptions.gridRow = app.SliderGridRow.Value;
app.GridRowsEditField.Value = app.SliderGridRow.Value;
end

% Value changed function: GridRowsEditField
function GridRowsEditFieldValueChanged(app, event)
value = app.GridRowsEditField.Value;
app.SliderGridRow.Value = value;
app.parameterOptions.gridRow = app.SliderGridRow.Value;
end

% Value changed function: GridColumnsEditField
function GridColumnsEditFieldValueChanged(app, event)
value = app.GridColumnsEditField.Value;
app.SliderGridCol.Value = value;
app.parameterOptions.gridColumn = app.SliderGridCol.Value;
end

% Value changed function: ParametersEditField
function ParametersEditFieldValueChanged(app, event)
value = app.ParametersEditField.Value;
app.SliderDensityParameter.Value = value;
app.parameterOptions.parameter_threshold = app.SliderDensityParameter.Value;
end
end

Expand Down Expand Up @@ -95,11 +205,11 @@ function createComponents(app)

% Create ImagetypeDropDown
app.ImagetypeDropDown = uidropdown(app.TumorRegionDetectionoptionsUIFigure);
app.ImagetypeDropDown.Items = {'H&E', 'Single channel', 'Two-channel', 'Others'};
app.ImagetypeDropDown.Items = {'HE bright field', 'Fluorescence_1-Channel', 'Fluorescence_2-Channel', 'Two-channel', 'Phase contrast', 'Gray scale'};
app.ImagetypeDropDown.DropDownOpeningFcn = createCallbackFcn(app, @ImagetypeDropDownValueChanged, true);
app.ImagetypeDropDown.ValueChangedFcn = createCallbackFcn(app, @ImagetypeDropDownValueChanged, true);
app.ImagetypeDropDown.Position = [210 335 173 22];
app.ImagetypeDropDown.Value = 'H&E';
app.ImagetypeDropDown.Value = 'HE bright field';

% Create DefaultparametersCheckBox
app.DefaultparametersCheckBox = uicheckbox(app.TumorRegionDetectionoptionsUIFigure);
Expand Down Expand Up @@ -144,6 +254,7 @@ function createComponents(app)

% Create GridColumnsEditField
app.GridColumnsEditField = uieditfield(app.TumorRegionDetectionoptionsUIFigure, 'numeric');
app.GridColumnsEditField.ValueChangedFcn = createCallbackFcn(app, @GridColumnsEditFieldValueChanged, true);
app.GridColumnsEditField.Position = [176 253 35 22];
app.GridColumnsEditField.Value = 50;

Expand All @@ -155,6 +266,7 @@ function createComponents(app)

% Create ParametersEditField
app.ParametersEditField = uieditfield(app.TumorRegionDetectionoptionsUIFigure, 'numeric');
app.ParametersEditField.ValueChangedFcn = createCallbackFcn(app, @ParametersEditFieldValueChanged, true);
app.ParametersEditField.Position = [178 173 33 22];
app.ParametersEditField.Value = 5;

Expand All @@ -166,26 +278,30 @@ function createComponents(app)

% Create GridRowsEditField
app.GridRowsEditField = uieditfield(app.TumorRegionDetectionoptionsUIFigure, 'numeric');
app.GridRowsEditField.ValueChangedFcn = createCallbackFcn(app, @GridRowsEditFieldValueChanged, true);
app.GridRowsEditField.Position = [178 212 36 22];
app.GridRowsEditField.Value = 50;

% Create SliderGridCol
app.SliderGridCol = uislider(app.TumorRegionDetectionoptionsUIFigure);
app.SliderGridCol.Position = [235 271 170 3];
app.SliderGridCol.ValueChangedFcn = createCallbackFcn(app, @SliderGridColValueChanged, true);
app.SliderGridCol.Position = [235 271 245 3];
app.SliderGridCol.Value = 50;

% Create SliderGrideRow
app.SliderGrideRow = uislider(app.TumorRegionDetectionoptionsUIFigure);
app.SliderGrideRow.Position = [235 222 170 3];
app.SliderGrideRow.Value = 50;
% Create SliderGridRow
app.SliderGridRow = uislider(app.TumorRegionDetectionoptionsUIFigure);
app.SliderGridRow.ValueChangedFcn = createCallbackFcn(app, @SliderGridRowValueChanged, true);
app.SliderGridRow.Position = [235 222 245 3];
app.SliderGridRow.Value = 50;

% Create SliderDensityParameter
app.SliderDensityParameter = uislider(app.TumorRegionDetectionoptionsUIFigure);
app.SliderDensityParameter.Limits = [0 10];
app.SliderDensityParameter.MajorTicks = [0 2 4 6 8 10];
app.SliderDensityParameter.MajorTickLabels = {'0', '2', '4', '6', '8', '10'};
app.SliderDensityParameter.MinorTicks = [1 2 3 4 5 6 7 8 9 10];
app.SliderDensityParameter.Position = [235 183 170 3];
app.SliderDensityParameter.Limits = [0 20];
app.SliderDensityParameter.MajorTicks = [0 5 10 15 20];
app.SliderDensityParameter.MajorTickLabels = {'0', '5', '10', '15', '20'};
app.SliderDensityParameter.ValueChangedFcn = createCallbackFcn(app, @SliderDensityParameterValueChanged, true);
app.SliderDensityParameter.MinorTicks = [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20];
app.SliderDensityParameter.Position = [235 183 245 3];
app.SliderDensityParameter.Value = 5;

% Show the figure after all components are created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ def cyto_seg(img_path,chan=[0,0]):
img = io.imread(img_path)
model = models.Cellpose(gpu=False, model_type='cyto')
mask, flows, styles, diams = model.eval(img, diameter=None, channels=chan)
sio.savemat('mask.mat', {'mask':mask})
sio.savemat('mask4cells.mat', {'mask4cells':mask})
return mask
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ def cyto_seg(img_path):
#print(im.shape)
app = CytoplasmSegmentation()
mask = app.predict(im)
sio.savemat('mask.mat', {'mask':mask})
sio.savemat('mask4cells.mat', {'mask4cells':mask})
return mask
27 changes: 23 additions & 4 deletions src/CurveAlign_CT-FIRE/Cellanalysis/WholeCell/imgCardWholeCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,32 @@
else
image = imageName;
end
pymatlabflag = 0; % didnot go through in matlab, pyenv terminated unexpectedly
if strcmp(model,'Cellpose') || strcmp(model,'DeepCell')
pymatlabflag = 1; % didnot go through in matlab, pyenv terminated unexpectedly
elseif strcmp(model,'FromMask-others')
pymatlabflag = 0;
end
if pymatlabflag ==1
wholeCellLink(image,model)
disp('running whole cell segmenation')
mask4cells = wholeCellLink(image,model);
else
fprintf('run the whole cell analysis outside the MATLAB environent \n')
[fileGet, pathGet]=uigetfile({'*.tif;*.mat','Tiff or MAT Files';'*.*','All Files'},...
'Select Cell mask file(s) from StarDist output',pwd,'MultiSelect','off');
if ischar(fileGet)
[~,~,fileType] = fileparts(fileGet);
if strcmp(fileType,'.mat')
load(fullfile(pathGet,fileGet),'mask4cells');
elseif strcmp(fileType,'.tif')
mask4cells = imread(fullfile(pathGet,fileGet));
else
error('This file %s is not a valid mask file \n', fullfile(pathGet,fileGet))
end
else
error('Previous segmented whole cell file is NOT loaded')
end

end
load('mask.mat','mask');
mask = mask4cells;
obj.cellArray = wholeCellCreation(imageName,mask,obj);
end
end
Expand Down
Binary file not shown.
Binary file modified src/CurveAlign_CT-FIRE/Cellanalysis/WholeCell/sample.tif
Binary file not shown.
23 changes: 15 additions & 8 deletions src/CurveAlign_CT-FIRE/Cellanalysis/WholeCell/wholeCellLink.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
function wholeCellLink(image,model)
function mask4cells = wholeCellLink(image,model)
% This function links deep learning models written in Python to MATLAB.
% image - the image that needs to be segmented
% model - two models available: 'Cellpose' and 'DeepCell'

%pe = pyenv;
pathToStardist = fileparts(which('cellpose_seg.py'));
if count(py.sys.path,pathToStardist) == 0
insert(py.sys.path,int32(0),pathToStardist);
end
% pathToStardist = fileparts(which('cellpose_seg.py'));
% if count(py.sys.path,pathToStardist) == 0
% insert(py.sys.path,int32(0),pathToStardist);
% end

if strcmp(model,'Cellpose')
% terminate(pyenv)
% pyenv('Version','C:\Users\liu372\.conda\envs\CApy311\python.exe', 'ExecutionMode', 'OutOfProcess')
py.cellpose_seg.cyto_seg(image);
py.importlib.import_module('cellpose_seg');
mask4cells= uint32(py.cellpose_seg.cyto_seg(image));

elseif strcmp(model,'DeepCell')
% terminate(pyenv)
% pyenv('Version','/Users/ympro/opt/anaconda3/envs/deepcell/bin/python')
py.deepcell_seg.cyto_seg(image);
end
py.importlib.import_module('deepcell_seg')
mask4cells = uint32(py.deepcell_seg.cyto_seg(image));
elseif strcmp(model,'FromMask')
cellobj = imgCardWholeCell(model,imageName,imagePath);
mask4cells = cellobj.cellArray.mask;

end

end
2 changes: 1 addition & 1 deletion src/CurveAlign_CT-FIRE/Cellanalysis/cellDensity.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [numCellsArray, minDistanceArray, numPixelsArray] = cellDensity(radius, stats)

load('details.mat','details')
load('details_sd.mat','details')
center = details.points;
numCellsTotal = length(center);

Expand Down
Binary file not shown.
Loading

0 comments on commit 27a07e5

Please sign in to comment.