-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageSeriesObject1.m
192 lines (189 loc) · 7.12 KB
/
ImageSeriesObject1.m
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
classdef ImageSeriesObject1 < dynamicprops
properties (SetAccess = protected)
imageHandles
imageVariables
imageMrrr
end
properties (SetAccess = immutable)
IMAGECLASS
end
methods
function obj = ImageSeriesObject1(varargin)
p = inputParser;
p.CaseSensitive = false;
defaultImageClass = 'CloudImageObject';
expectedImageClass = {'AbsorptionImageObject','CloudImageObject'};
addOptional(p,'imageclass',defaultImageClass,@(x) any(validatestring(x,expectedImageClass)));
addOptional(p,'files','');
addOptional(p,'magnification',.25,@isnumeric);
parse(p,varargin{:});
obj.IMAGECLASS = p.Results.imageclass;
magnification = p.Results.magnification;
files = p.Results.files;
delete(p);
if isempty(files)
[filenames, path] = ImageSeriesObject1.selectFiles('D:\Data\Current');
else
filenames = files;
path = pwd;
end
imageFilenamesStart=filenames(1);
imageFilenamesEnd=filenames(length(filenames));
%imageFilenamesList=[imageFilenamesStart imageFilenamesEnd];
imageMrrr=5;
for i = 1:length(filenames)
if i == 1
tempObj = CloudImageObject('magnification',magnification,'file',[path filenames{i}]);
obj.imageVariables = tempObj.variables;
else
tempObj=CloudImageObject('magnification',magnification,'file',[path filenames{i}],'resetROI',false);
if ~ ismember(tempObj.variables, obj.imageVariables)
error('Variable mismatch between members of image series!');
end
end
obj.imageHandles{i} = tempObj;
assignin('base', genvarname(filenames{i}), obj.imageHandles{i});
end
end
function addImages(obj, varargin)
if nargin
filenames=varargin{1};
path=pwd;
else
[filenames, path] = ImageSeriesObject1.selectFiles();
end
iStart=length(obj.imageHandles);
for i=1:length(filenames)
tempObj=CloudImageObject('file',[path filenames{i}]);
if ~ tempObj.variables == obj.imageVariables
error('Variable mismatch between members of image series!')
end
obj.imageHandles{iStart+i}=tempObj;
assignin('base',genvarname(filenames{i}),obj.imageHandles{iStart+i});
end
end
function removeImage(obj, varargin)
if ~nargin
error('No Input')
elseif isnumeric(varargin)
%%stuff
else
error('Input not image index')
end
end
function varargout = show(obj,varargin)
numberOfImages=length(obj.imageHandles);
if (nargin-1)
[imlist,proplist]=obj.orderedList(varargin{1});
figureTitle=varargin{1};
else
imlist=obj.imageHandles;
for i=1:numberOfImages
filename=obj.imageHandles{i}.filename;
proplist{i}=['...' filename(12:19)];
end
figureTitle='filename';
end
for i=1:numberOfImages
images{i}=imresize(imlist{i}.normalizedImage,.2);
end
h = figure('name',figureTitle);
text(.25,1.25,figureTitle)
hold on
a=gca;
columns=5;
rows=mod(numberOfImages,columns);
for i=1:numberOfImages
subplot(rows,columns,i)
imshow(images{i},'Border','tight')
title(proplist(i))
end
varargout{1}=h;
hold off
end
function movie = showMovie(obj,prop)
end
function tf=isprop(obj,prop)
tf=true;
i=1;
while tf && i<=length(obj.imageHandles)
if ~isprop(obj.imageHandles{i},prop)
tf = false;
end
i=i+1;
end
end
function [imageList,varList] = orderedList(obj,prop)
if isprop(obj,prop)
for i=1:length(obj.imageHandles)
varList(i)=obj.imageHandles{i}.(prop);
imageList(i)=obj.imageHandles(i);
end
[varList,sortIndex]=sort(varList);
imageList=imageList(sortIndex);
else
error('Property not found in series!')
end
end
function varargout = plot(obj,xProp,yProp)
varargout={};
if isprop(obj,xProp) && isprop(obj,yProp)
for i=1:length(obj.imageHandles)
xPropList(i)=obj.imageHandles{i}.(xProp);
yPropList(i)=obj.imageHandles{i}.(yProp);
end
h = plot(xPropList,yPropList,'b*');
ylabel(yProp)
xlabel(xProp)
title([yProp ' vs ' xProp])
varargout{1}=h;
else
error([xProp ' and ' yProp ' are not properties of all objects in the series.'])
end
end
function varargout = ploterr(obj,xProp,yProp)
varargout={};
if isprop(obj,xProp) && isprop(obj,yProp)
for i=1:length(obj.imageHandles)
xPropList(i)=obj.imageHandles{i}.(xProp);
yPropList(i)=obj.imageHandles{i}.(yProp);
end
xBinned=unique(xPropList);
for i=1:length(xBinned)
yBinned(i) = mean(yPropList(xPropList == xBinned(i)));
yBinnedSTD(i) = std(yPropList(xPropList == xBinned(i)))/sqrt(length(yBinned(i)));
end
h = errorbar(xBinned,yBinned,yBinnedSTD,'b*');
ylabel(yProp)
xlabel(xProp)
title([yProp ' vs ' xProp])
varargout{1}=h;
end
end
function hlist = findImagesWithProp(obj,PropName,PropValue)
hlist=[];
for i=1:length(obj.imageHandles)
if isprop(obj.imageHandles{i},PropName)
if obj.imageHandles{i}.(PropName)==PropValue
hlist(length(hlist)+1)=obj.imageHandles{i};
end
end
end
end
end
methods (Access = protected)
function makeLegend(obj,property)
if isprop(obj,property)
legend=cell(1,length(obj.imageHandles));
for i=1:length(obj.imageHandles)
legend{i}=num2str(obj.imageHandles{i}.(property));
end
end
end
end
methods ( Static = true)
[filenames, filepaths] = selectFiles(varargin) %UI to select a file
objList = findall()
h = displaySeries(varargin)
end
end