322 {
325 int b = pl.getBitDepth();
326 int slices = pl.getNSlices();
327 int chs = pl.getNChannels();
328 int frs = pl.getNFrames();
329 int rgb = (int)(pl.getBytesPerPixel() * 8);
330 bool isrgb =
isRGB(pl);
333 AForge.Bitmap[] outputBuffers = new AForge.Bitmap[Math.Max(1, slices * chs * frs)];
334 for (int t = 0; t < frs; t++)
335 {
336 for (int z = 0; z < slices; z++)
337 {
338 for (int c = 0; c < chs; c++)
339 {
340 AForge.Bitmap bmp;
341 if (!isrgb)
342 {
343 if (rgb > 8)
344 {
345 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format16bppGrayScale);
346 }
347 else
348 {
349 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format8bppIndexed);
350 }
351 }
352 else
353 {
354 bmp = new AForge.Bitmap(st.getWidth(), st.getHeight(), AForge.PixelFormat.Format24bppRgb);
355 }
356 int ind =
bm.GetFrameIndex(z, c, t);
357 int stackIndex = GetHyperStackSliceIndex(pl, z, c, t);
358 outputBuffers[ind] = bmp;
359 if (!isrgb)
360 {
361 for (int y = 0; y < pl.getHeight(); y++)
362 {
363 for (int x = 0; x < pl.getWidth(); x++)
364 {
365 double d = st.getVoxel(x, y, stackIndex);
366 if (bmp.PixelFormat ==
PixelFormat.Format16bppGrayScale)
367 bmp.SetValue(x, y, (ushort)d);
368 else if (bmp.PixelFormat ==
PixelFormat.Format8bppIndexed)
369 bmp.SetValue(x, y, (byte)d);
370 }
371 }
372 }
373 else
374 {
376
378 for (int y = 0; y < pl.getHeight(); y++)
379 {
380 for (int x = 0; x < pl.getWidth(); x++)
381 {
382 int v = colorProcessor.getPixel(x, y);
383 int rv = (v >> 16) & 0xFF;
384 int gv = (v >> 8) & 0xFF;
385 int bv = v & 0xFF;
386 bmp.SetValue(x, y, 0, (byte)rv);
387 bmp.SetValue(x, y, 1, (byte)gv);
388 bmp.SetValue(x, y, 2, (byte)bv);
389 }
390 }
391
392 }
393 }
394 }
395 }
396 bm.Buffers.AddRange(outputBuffers.Where(buf => buf !=
null));
397 for (int t = 0; t < chs; t++)
398 {
399 if (isrgb)
400 bm.Channels.Add(
new AForge.Channel(t, rgb, 3));
401 else
402 bm.Channels.Add(
new AForge.Channel(t, rgb, 1));
403 if (t == 0)
404 {
405 bm.rgbChannels[0] = 0;
406 }
407 else
408 if (t == 1)
409 {
410 bm.rgbChannels[1] = 1;
411 }
412 else
413 if (t == 2)
414 {
415 bm.rgbChannels[2] = 2;
416 }
417 }
418 bm.Resolutions.Add(
new Resolution(pl.getWidth(), pl.getHeight(),
bm.Buffers[0].PixelFormat, PhysicalX, PhysicalY, PhysicalZ, vol.Location.X, vol.Location.Y, vol.Location.X));
419 bm.Volume = vol;
420 bm.littleEndian = BitConverter.IsLittleEndian;
421 bm.seriesCount = 1;
423 if (rgb > 8)
424 bm.StackThreshold(
true);
425 else
426 bm.StackThreshold(
false);
427
428 if (
bm.RGBChannelCount == 4)
429 {
430 bm.Channels.Last().SamplesPerPixel = 4;
431 }
433 }
AForge.PixelFormat PixelFormat
Definition Bio.cs:58
return b
Definition Bio.cs:7393
static Bitmap bm
Definition Bio.cs:8524
FijiNet::ij.process.ColorProcessor ColorProcessor
Definition Fiji.cs:18
FijiNet::ij.ImageStack ImageStack
Definition Fiji.cs:24
FijiNet::ij.process.ImageProcessor ImageProcessor
Definition Fiji.cs:23
Order
Definition Bio.cs:2898
static bool isRGB(ImagePlus image)
Definition Fiji.cs:299