108 {
109 ReConnect();
110 try
111 {
112 BioImage b = new BioImage("test.ome.tif");
113 java.util.Collection col = new java.util.ArrayList();
114 col.add(java.lang.Long.valueOf(dataset));
115 var uims = browsefacil.getImagesForDatasets(sc, col);
116 var itr = uims.iterator();
117 java.util.List li = new java.util.ArrayList();
118 java.util.ArrayList imgs = new java.util.ArrayList();
119 do
120 {
121 java.util.ArrayList list = new java.util.ArrayList();
122 ImageData o = (ImageData)itr.next();
123 string name = o.getName();
124 if (name != filename)
125 continue;
126 PixelsData pd = o.getDefaultPixels();
127 int xs = pd.getSizeX();
128 int ys = pd.getSizeY();
129 int zs = pd.getSizeZ();
130 int cs = pd.getSizeC();
131 int ts = pd.getSizeT();
132 long pid = o.getId();
133
134 b.Filename = name;
135 b.ID = name;
136 RawPixelsStorePrx store = gateway.getPixelsStore(sc);
137 long ind = o.getId();
138 long ll = pd.getId();
139 list.add(java.lang.Long.valueOf(ind));
140 try
141 {
142 var acq = metafacil.getChannelData(sc, ind);
143 int s = acq.size();
144 for (int i = 0; i < s; i++)
145 {
146 var ch = (ChannelData)acq.get(i);
147 var ac = metafacil.getImageAcquisitionData(sc, ind);
148 var chan = ch.asChannel();
149 AForge.Color color = AForge.Color.FromArgb(chan.getRed().getValue(), chan.getGreen().getValue(), chan.getBlue().getValue());
150 var px = pd.asPixels().getPixelsType();
151 int bits = px.getBitSize().getValue();
152 AForge.PixelFormat pxx = GetPixelFormat(bits);
153 AForge.Channel cch = null;
154 if (pxx == AForge.PixelFormat.Format8bppIndexed || pxx == AForge.PixelFormat.Format16bppGrayScale)
155 cch = new AForge.Channel(i, bits, 1);
156 else if (pxx == AForge.PixelFormat.Format24bppRgb || pxx == AForge.PixelFormat.Format48bppRgb)
157 cch = new AForge.Channel(i, bits, 3);
158 else if (pxx == AForge.PixelFormat.Format32bppArgb)
159 cch = new AForge.Channel(i, bits, 4);
160 cch.Fluor = ch.getFluor();
161 var em = ch.getEmissionWavelength(Omero::omero.model.enums.UnitsLength.NANOMETER);
162 if (em != null)
163 cch.Emission = (int)em.getValue();
164 cch.Color = color;
165 cch.Name = ch.getName();
166 if (cch.Name == null)
167 cch.Name = i.ToString();
168 b.Channels.Add(cch);
169 }
170 }
171 catch (Exception exx)
172 {
173 Console.WriteLine(exx.Message);
174 }
175 var stage = o.asImage().getStageLabel();
176
177 try
178 {
179 int i = 0;
180 while(true)
181 {
182 Omero.omero.RInt rint = rtypes.rint(i);
183 Image im = o.asImage();
184 im.setSeries(rint);
185 RInt rin = im.getSeries();
186 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
187 Pixels pxs = im.getPixels(0);
188 store.setPixelsId(pxs.getId().getValue(),true);
189 if(!store.requiresPixelsPyramid())
190 {
191 var pxto = pxs.getPixelsType();
192 int bitso = pxto.getBitSize().getValue();
193 int wo = pxs.getSizeX().getValue();
194 int ho = pxs.getSizeY().getValue();
195 px = GetPixelFormat(bitso);
196 double pxxo = pxs.getPhysicalSizeX().getValue();
197 double pyyo = pxs.getPhysicalSizeY().getValue();
198 double pzzo = 0;
199 var pzo = pxs.getPhysicalSizeZ();
200 if (pzo != null)
201 pzzo = pzo.getValue();
202 if (stage != null)
203 {
204 var sta = (StageLabel)session.getQueryService().get("StageLabel", o.asImage().getStageLabel().getId().getValue());
205 Length? sxxo = sta.getPositionX();
206 Length? syyo = sta.getPositionY();
207 Length? szzo = sta.getPositionZ();
208 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo * wo, pyyo * ho, pzzo, sxxo.getValue(), syyo.getValue(), szzo.getValue()));
209 }
210 else
211 b.Resolutions.Add(new Resolution(wo, ho, px, pxxo * wo, pyyo * ho, pzzo, 0, 0, 0));
212 break;
213 }
214 else
215 {
216 b.Type = BioImage.ImageType.pyramidal;
217 }
218 if (i == store.getResolutionLevels())
219 break;
220 var ress = store.getResolutionDescriptions();
221 var re = ress[i];
222 var pxt = pxs.getPixelsType();
223 int bits = pxt.getBitSize().getValue();
224 int w = re.sizeX;
225 int h = re.sizeY;
226 px = GetPixelFormat(bits);
227 double pxx = pxs.getPhysicalSizeX().getValue();
228 double pyy = pxs.getPhysicalSizeY().getValue();
229 double pzz = 0;
230 var pz = pxs.getPhysicalSizeZ();
231 if(pz != null)
232 pzz = pz.getValue();
233 if (stage != null)
234 {
235 var sta = (StageLabel)session.getQueryService().get("StageLabel", o.asImage().getStageLabel().getId().getValue());
236 Length? sxx = sta.getPositionX();
237 Length? syy = sta.getPositionY();
238 Length? szz = sta.getPositionZ();
239 b.Resolutions.Add(new Resolution(w, h, px, pxx, pyy, pzz, sxx.getValue(), syy.getValue(), szz.getValue()));
240 }
241 else
242 b.Resolutions.Add(new Resolution(w, h, px, pxx, pyy, pzz, 0, 0, 0));
243 i++;
244 }
245 }
246 catch (Exception ex)
247 {
248 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
249 var pxt = pd.asPixels().getPixelsType();
250 int bits = pxt.getBitSize().getValue();
251 px = GetPixelFormat(bits);
252 double pxx = pd.asPixels().getPhysicalSizeX().getValue();
253 double pyy = pd.asPixels().getPhysicalSizeY().getValue();
254 double pzz = 0;
255 var pz = pd.asPixels().getPhysicalSizeZ();
256 if (pz != null)
257 pzz = pz.getValue();
258 if (stage != null)
259 {
260 if (stage.isLoaded())
261 {
262 Length? sxx = stage.getPositionX();
263 Length? syy = stage.getPositionY();
264 Length? szz = stage.getPositionZ();
265 b.Resolutions.Add(new Resolution(xs, ys, px, pxx, pyy, pzz, sxx.getValue(), syy.getValue(), szz.getValue()));
266 }
267 }
268 else
269 b.Resolutions.Add(new Resolution(xs, ys, px, pxx, pyy, pzz, 0, 0, 0));
270 }
271
272 for (int z = 0; z < zs; z++)
273 {
274 for (int c = 0; c < cs; c++)
275 {
276 for (int t = 0; t < ts; t++)
277 {
278 if (b.isPyramidal)
279 {
280 Pixels ps = pd.asPixels();
281 int chc = ps.sizeOfChannels();
282 store.setPixelsId(ps.getId().getValue(), true);
283 store.setResolutionLevel(0);
284 if (xs > 1920 || ys > 1080)
285 {
286 byte[] bts = store.getTile(z, c, t, 0, 0, 1920, 1080);
287 PixelsType pxt = ps.getPixelsType();
288 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
289 int bits = pxt.getBitSize().getValue();
290 px = GetPixelFormat(bits);
291 b.Buffers.Add(new AForge.Bitmap("", 1920, 1080, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
292 }
293 else
294 {
295 byte[] bts = store.getTile(z, c, t, 0, 0, xs, ys);
296 PixelsType pxt = ps.getPixelsType();
297 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
298 int bits = pxt.getBitSize().getValue();
299 px = GetPixelFormat(bits);
300 b.Buffers.Add(new AForge.Bitmap("", xs, ys, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
301 }
302 }
303 else
304 {
305 Pixels ps = pd.asPixels();
306 int chc = ps.sizeOfChannels();
307 store.setPixelsId(ps.getId().getValue(), true);
308 byte[] bts = store.getPlane(z, c, t);
309 PixelsType pxt = ps.getPixelsType();
310 AForge.PixelFormat px = AForge.PixelFormat.Format8bppIndexed;
311 int bits = pxt.getBitSize().getValue();
312 px = GetPixelFormat(bits);
313 b.Buffers.Add(new AForge.Bitmap("", xs, ys, px, bts, new AForge.ZCT(z, c, t), 0, null, false));
314 }
315 }
316 }
317 }
318 b.UpdateCoords(zs, cs, ts);
319 b.Volume = new VolumeD(new Point3D(b.StageSizeX, b.StageSizeY, b.StageSizeZ), new Point3D(b.SizeX * b.PhysicalSizeX, b.SizeY * b.PhysicalSizeY, b.SizeZ * b.PhysicalSizeZ));
320 b.bitsPerPixel = b.Buffers[0].BitsPerPixel;
321 b.series = o.getSeries();
322 b.imagesPerSeries = b.Buffers.Count;
323 b.rgbChannels = new int[b.Channels.Count];
324 b.rgbChannels[0] = 0;
325 b.rgbChannels[1] = 1;
326 b.rgbChannels[2] = 2;
327 BioImage.AutoThreshold(b, true);
328 if (b.bitsPerPixel > 8)
329 b.StackThreshold(true);
330 else
331 b.StackThreshold(false);
332 b.Tag = "OMERO";
333 if(b.isPyramidal)
334 {
335 b.SlideBase = new SlideBase(b, SlideImage.Open(b));
336 }
337 return b;
338 }
339 while (itr.hasNext());
340 }
341 catch (Exception e)
342 {
343 Console.WriteLine(e.ToString());
344 }
345 return null;
346 }