-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell_brightness_estimator.asv
More file actions
70 lines (57 loc) · 2.38 KB
/
cell_brightness_estimator.asv
File metadata and controls
70 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
% cell_brightness_estimator
% EJR, 2016, CC-BY
%
% Approximately follows the cell-brightness estimating macro from
% CHMM / GS, for sample image data of Gen Simpson
%
% Instructions:
% 1. Run this script in Matlab
% 2. Use the "open file" GUI to select one file of raw image data
% 3. This script then attempts to process each image file in the same
% folder
%
% Notes:
% 1. The background estimation parameter can be edited in section 0
% 2. Sample image data seems to 8-bit values stored in a 32-bit tif
% (It seems possible my recommendations on file types have gone astray:
% because the 8-bit values may have been rescaled! But maybe not - max
% values of 203 (not 255) are identifiable.)
% 0. Settings
% Settings for running this script
backgroundP = 0.25; % Set 0.25 to estimate the 25th percentile of imDat(:) as the d.c. background
threshParam = 0.25; % Set a value between 0 and 1.
maskErodeRad = 4; % Might need an erosion filter - set radius here
erodeStrel = strel('disk',maskErodeRad);
% 1. Input
% (a) User specifies target folder
% (b) Create empty lists to store the results for each Tif in the folder
[FileNameSample,PathName] = uigetfile('*.tif',...
'Open image data file in target folder (Tif)');
listOfFiles = dir([PathName,'*.tif']);
numberOfFiles = length(listOfFiles);
% Preallocate a list to store detected 'cell' areas and intensities.
% Residual '-1' values at the end can be interpretted as an error
listAreas = -ones(numberOfFiles, 1); % Area in pixels
listBrightness = -ones(numberOfFiles, 1); % Mean raw brightness of ROIs
listMax = -ones(numberOfFiles, 1); % Max pixel value in imDat
listMin = -ones(numberOfFiles, 1); % Min pixel value in imDat
listBGestimate = -ones(numberOfFiles, 1); % DC background level estimate
% 2. Analyse
% (a) Process each file in the chosen folder in series
% (b) Try to detect cell area and (pixel-average) brightness
for lpIm = 1:numberOfFiles
imDat = imread([PathName,listOfFiles(lpIm).name]);
imMax = max(imDat(:));
imMin = min(imDat(:));
imBG = quantile(imDat(:), backgroundP);
imTh = imBG + threshParam * (imMax - imBG);
imCut = imDat;
imCut(imMsk)
imMsk = (imDat > imTh);
figure(1)
imagesc(imDat.*imMsk);
colormap(gray)
end
% 3. Output
% (a) Results should now be sitting in the listXXXX arrays
% (b) Possibly export the results to a CSV spreadsheet