private static TifFileInfo TrackCropToolStripMenuItem_click(ROI roi, string dir, TifFileInfo fi) { ROI oldROI = roi; roi = ROITransformer.ROIEditor.TransformToRect(fi, roi); if (roi == null) { return(null); } fi.available = false; TifFileInfo newFI = null; //crop the rectangle newFI = DuplicateFI(fi); newFI.Dir = newFI.Dir.Substring(0, newFI.Dir.LastIndexOf(".")) + "_ROI" + (fi.roiList[fi.cValue].IndexOf(roi) + 1).ToString() + ".tif"; Size size = new Size(roi.Width, roi.Height); newFI.sizeX = roi.Width; newFI.sizeY = roi.Height; newFI.xCompensation = 0; newFI.yCompensation = 0; newFI.imageCount = fi.imageCount; newFI.openedImages = newFI.imageCount; AddEmptyArraysToFI(newFI); Point[] locs = roi.GetLocationAll()[0]; switch (fi.bitsPerPixel) { case 8: byte[][][] image8bit = new byte[fi.imageCount][][]; Parallel.For(0, fi.imageCount, frame => { Point location = locs[frame]; Rectangle rect = new Rectangle(location, size); image8bit[frame] = new byte[rect.Height][]; for (int y = rect.Y, yNew = 0; y < rect.Y + rect.Height; y++, yNew++) { image8bit[frame][yNew] = new byte[rect.Width]; for (int x = rect.X, xNew = 0; x < rect.X + rect.Width; x++, xNew++) { if (x >= 0 && y >= 0 && x < fi.sizeX && y < fi.sizeY) { image8bit[frame][yNew][xNew] = fi.image8bit[frame][y][x]; } } } }); newFI.image8bit = image8bit; newFI.image8bitFilter = newFI.image8bit; break; case 16: ushort[][][] image16bit = new ushort[fi.imageCount][][]; Parallel.For(0, fi.imageCount, frame => { Point location = locs[frame]; Rectangle rect = new Rectangle(location, size); image16bit[frame] = new ushort[rect.Height][]; for (int y = rect.Y, yNew = 0; y < rect.Y + rect.Height; y++, yNew++) { image16bit[frame][yNew] = new ushort[rect.Width]; for (int x = rect.X, xNew = 0; x < rect.X + rect.Width; x++, xNew++) { if (x >= 0 && y >= 0 && x < fi.sizeX && y < fi.sizeY) { image16bit[frame][yNew][xNew] = fi.image16bit[frame][y][x]; } } } }); newFI.image16bit = image16bit; newFI.image16bitFilter = newFI.image16bit; break; } newFI.loaded = true; newFI.original = false; //FileEncoder.SaveTif(newFI, dir); fi.available = true; RecalculateOriginalROI(oldROI, roi, newFI); return(newFI); }
private static string calculateCTTagValue(TifFileInfo fi) { List <string> vals = new List <string>(); try { vals.Add("seriesCount->" + fi.seriesCount.ToString()); vals.Add("imageCount->" + fi.imageCount.ToString()); vals.Add("sizeX->" + fi.sizeX.ToString()); vals.Add("sizeY->" + fi.sizeY.ToString()); vals.Add("sizeC->" + fi.sizeC.ToString()); vals.Add("sizeZ->" + fi.sizeZ.ToString()); vals.Add("sizeT->" + fi.sizeT.ToString()); vals.Add("umXY->" + fi.umXY.ToString()); vals.Add("umZ->" + fi.umZ.ToString()); vals.Add("bitsPerPixel->" + fi.bitsPerPixel.ToString()); vals.Add("dimensionOrder->" + fi.dimensionOrder); vals.Add("pixelType->" + fi.pixelType.ToString()); vals.Add("FalseColored->" + fi.FalseColored.ToString()); vals.Add("isIndexed->" + fi.isIndexed.ToString()); vals.Add("MetadataComplete->" + fi.MetadataComplete.ToString()); vals.Add("DatasetStructureDescription->" + fi.DatasetStructureDescription); vals.Add("Micropoint->" + fi.Micropoint.ToString()); vals.Add("autoDetectBandC->" + fi.autoDetectBandC.ToString()); vals.Add("applyToAllBandC->" + fi.applyToAllBandC.ToString()); vals.Add("xCompensation->" + fi.xCompensation.ToString()); vals.Add("yCompensation->" + fi.yCompensation.ToString()); vals.Add("DataSourceInd->" + fi.DataSourceInd.ToString()); vals.Add("LutList->" + TagValueToString(fi.LutList)); vals.Add("TimeSteps->" + TagValueToString(fi.TimeSteps)); if (fi.MinBrightness != null) { vals.Add("MinBrightness->" + TagValueToString(fi.MinBrightness)); } else { int[] a = new int[fi.sizeC]; vals.Add("MinBrightness->" + TagValueToString(a)); } if (fi.MaxBrightness != null) { vals.Add("MaxBrightness->" + TagValueToString(fi.MaxBrightness)); } else { int[] a = new int[fi.sizeC]; int c1 = 250; if (fi.bitsPerPixel != 8) { c1 = 16000; } for (int i = 0; i < a.Length; i++) { a[i] = c1; } vals.Add("MaxBrightness->" + TagValueToString(a)); } vals.Add("tracking_MaxSize->" + TagValueToString(fi.tracking_MaxSize)); vals.Add("tracking_MinSize->" + TagValueToString(fi.tracking_MinSize)); vals.Add("tracking_Speed->" + TagValueToString(fi.tracking_Speed)); vals.Add("SegmentationProtocol->" + TagValueToString(fi.SegmentationProtocol)); vals.Add("SegmentationCBoxIndex->" + TagValueToString(fi.SegmentationCBoxIndex)); vals.Add("thresholdsCBoxIndex->" + TagValueToString(fi.thresholdsCBoxIndex)); vals.Add("SelectedSpotThresh->" + TagValueToString(fi.SelectedSpotThresh)); vals.Add("typeSpotThresh->" + TagValueToString(fi.typeSpotThresh)); vals.Add("SpotThresh->" + TagValueToString(fi.SpotThresh)); vals.Add("spotSensitivity->" + TagValueToString(fi.spotSensitivity)); vals.Add("thresholds->" + TagValueToString(fi.thresholds)); vals.Add("SpotColor->" + TagValueToString(fi.SpotColor)); vals.Add("RefSpotColor->" + TagValueToString(fi.RefSpotColor)); vals.Add("sumHistogramChecked->" + TagValueToString(fi.sumHistogramChecked)); vals.Add("SpotTailType->" + string.Join("\t", fi.SpotTailType)); vals.Add("thresholdColors->" + TagValueToString(fi.thresholdColors)); vals.Add("RefThresholdColors->" + TagValueToString(fi.RefThresholdColors)); vals.Add("thresholdValues->" + TagValueToString(fi.thresholdValues)); vals.Add("FileDescription->" + fi.FileDescription); vals.Add("xAxisTB->" + fi.xAxisTB.ToString()); vals.Add("yAxisTB->" + fi.yAxisTB.ToString()); //Roi part int c = 0; foreach (List <ROI> roiList in fi.roiList) { if (roiList != null) { foreach (ROI roi in roiList) { string str = "roi.new->" + roi_new(c, roi); vals.Add(str); } } c++; } //it is important FilterHistory to be the last vals.Add("FilterHistory->" + TagValueToString(fi.FilterHistory.ToArray())); } catch { System.Windows.Forms.MessageBox.Show(vals[vals.Count - 1]); } return(string.Join(";\n", vals)); }
private static TifFileInfo CropToolStripMenuItem_click(ROI roi, string dir, TifFileInfo fi) { if (roi.Type == 1) { return(TrackCropToolStripMenuItem_click(roi, dir, fi)); } return(null); fi.available = false; TifFileInfo newFI = null; Rectangle rect = Rectangle.Empty; //find rectangles switch (roi.Type) { case 0: if (roi.Shape == 1 | roi.Shape == 0) { Point p = roi.GetLocation(fi.cValue)[0]; Size size = new Size(roi.Width, roi.Height); rect = new Rectangle(p, size); } else if (roi.Shape == 2 || roi.Shape == 3 || roi.Shape == 4 || roi.Shape == 5) { Point[] pList = roi.GetLocation(fi.cValue); int X = int.MaxValue; int Y = int.MaxValue; int W = int.MinValue; int H = int.MinValue; foreach (Point p1 in pList) { if (p1.X < X) { X = p1.X; } if (p1.Y < Y) { Y = p1.Y; } if (p1.X > W) { W = p1.X; } if (p1.Y > H) { H = p1.Y; } } Point p = new Point(X, Y); Size size = new Size(W - X, H - Y); rect = new Rectangle(p, size); } break; case 1: if (roi.Shape == 1 | roi.Shape == 0) { Point[] pList = roi.GetLocationAll()[0]; int X = int.MaxValue; int Y = int.MaxValue; int W = int.MinValue; int H = int.MinValue; for (int i = fi.cValue; i < fi.imageCount; i += fi.sizeC) { Point p1 = pList[i]; if (p1 != null) { if (p1.X < X) { X = p1.X; } if (p1.Y < Y) { Y = p1.Y; } if (p1.X > W) { W = p1.X; } if (p1.Y > H) { H = p1.Y; } } } Point p = new Point(X, Y); Size size = new Size(W - X + roi.Width, H - Y + roi.Height); rect = new Rectangle(p, size); } else if (roi.Shape == 2 || roi.Shape == 3 || roi.Shape == 4 || roi.Shape == 5) { int X = int.MaxValue; int Y = int.MaxValue; int W = int.MinValue; int H = int.MinValue; Point[] pList; for (int i = fi.cValue; i < fi.imageCount; i += fi.sizeC) { pList = roi.GetLocation(i); foreach (Point p1 in pList) { if (p1.X < X) { X = p1.X; } if (p1.Y < Y) { Y = p1.Y; } if (p1.X > W) { W = p1.X; } if (p1.Y > H) { H = p1.Y; } } } Point p = new Point(X, Y); Size size = new Size(W - X, H - Y); rect = new Rectangle(p, size); } break; } //crop the rectangle newFI = DuplicateFI(fi); newFI.Dir = newFI.Dir.Substring(0, newFI.Dir.LastIndexOf(".")) + "_ROI" + (fi.roiList[fi.cValue].IndexOf(roi) + 1).ToString() + ".tif"; newFI.sizeX = rect.Width; newFI.sizeY = rect.Height; newFI.xCompensation = rect.X; newFI.yCompensation = rect.Y; newFI.imageCount = fi.imageCount; newFI.openedImages = newFI.imageCount; AddEmptyArraysToFI(newFI); switch (fi.bitsPerPixel) { case 8: byte[][][] image8bit = new byte[fi.imageCount][][]; Parallel.For(0, fi.imageCount, frame => { image8bit[frame] = new byte[rect.Height][]; for (int y = rect.Y, yNew = 0; y < rect.Y + rect.Height; y++, yNew++) { image8bit[frame][yNew] = new byte[rect.Width]; for (int x = rect.X, xNew = 0; x < rect.X + rect.Width; x++, xNew++) { if (x >= 0 && y >= 0 && x < fi.sizeX && y < fi.sizeY) { image8bit[frame][yNew][xNew] = fi.image8bit[frame][y][x]; } } } }); newFI.image8bit = image8bit; newFI.image8bitFilter = newFI.image8bit; break; case 16: ushort[][][] image16bit = new ushort[fi.imageCount][][]; Parallel.For(0, fi.imageCount, frame => { image16bit[frame] = new ushort[rect.Height][]; for (int y = rect.Y, yNew = 0; y < rect.Y + rect.Height; y++, yNew++) { image16bit[frame][yNew] = new ushort[rect.Width]; for (int x = rect.X, xNew = 0; x < rect.X + rect.Width; x++, xNew++) { if (x >= 0 && y >= 0 && x < fi.sizeX && y < fi.sizeY) { image16bit[frame][yNew][xNew] = fi.image16bit[frame][y][x]; } } } }); newFI.image16bit = image16bit; newFI.image16bitFilter = newFI.image16bit; break; } newFI.loaded = true; newFI.original = false; //FileEncoder.SaveTif(newFI, dir); fi.available = true; return(newFI); }