private void sum_Click(object sender, RoutedEventArgs e) { ImageSlice slice = _imageData[_imageData.Count - 2] + _imageData[_imageData.Count - 1]; AddImage(slice, slice.sliceFileName); activate_deactivate_Buttons(); }
private void difference_ClickBA(object sender, RoutedEventArgs e) { ImageSlice slice = _imageData[_imageData.Count - 1] - _imageData[_imageData.Count - 2]; AddImage(slice, slice.sliceFileName); activate_deactivate_Buttons(); }
private void AddImage(ImageSlice slice, string sliceName) { // insert new data image slice.sliceFileName = sliceName; _imageData.Add(slice); // update combobox ComboboxItem item = new ComboboxItem(); item.Text = sliceName; item.Value = _numImage; fileNameBox.Items.Add(item); fileNameBox.SelectedIndex = fileNameBox.Items.Count - 1; _numImage++; if (_imageData[fileNameBox.SelectedIndex].zeroIntensity == -1) { zeroBond.Content = ""; zeroBond.DataContext = 0.5; } else { zeroBond.Content = Convert.ToString(getZeroPointSlider()); zeroBond.DataContext = _imageData[fileNameBox.SelectedIndex].zeroIntensity; } }
private void save_Statistics_Click(object sender, RoutedEventArgs e) { if (fileNameBox.SelectedIndex == -1) { throw new System.Exception("No image loaded, cannot export!"); } if (selectionBox.Visibility != Visibility.Visible) { throw new System.Exception("No selection availible!"); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "TXT files (*.TXT)|*.txt|All files (*.*)|*.*"; if (saveFileDialog.ShowDialog() == true) { using (var fileStream = new StreamWriter(saveFileDialog.FileName)) { ImageSlice slices = _imageData[fileNameBox.SelectedIndex]; fileStream.WriteLine("Slice\tAvarage\tStdDev\t#Points\tsizeX({0})\tsizeY({0})\tsizeZ({0})", slices.realUnit); for (int i = 1; i <= slices.zSize; i++) { var r = convertSelectionToRect(slices); var stats = slices.GetStatistics(r, i); var dim = slices.GetDimensions(r); fileStream.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t", i, stats.Item1, stats.Item2, stats.Item3, dim.Item1, dim.Item2, dim.Item3); } } } }
private void avg3_Click(object sender, RoutedEventArgs e) { ImageSlice slice = (_imageData[_imageData.Count - 3] + _imageData[_imageData.Count - 2] + _imageData[_imageData.Count - 1]) / 3; AddImage(slice, slice.sliceFileName); activate_deactivate_Buttons(); statistics(slice); }
private void ReplaceImage(ImageSlice slice, string sliceName) { // replace data image slice.sliceFileName = sliceName; _imageData[fileNameBox.SelectedIndex] = slice; // update combobox (fileNameBox.Items[fileNameBox.SelectedIndex] as ComboboxItem).Text = sliceName; // update Image NumSlice = _numSlice; }
private void replace_Click(object sender, RoutedEventArgs e) { if (fileNameBox.SelectedIndex == -1) { throw new System.Exception("No image selected, cannot replace!"); } OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { // load image from file ImageSlice slice = new ImageSlice(openFileDialog.FileName); _numSlice = 1; // update text field txtNum.Text = _numSlice.ToString(); ReplaceImage(slice, System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName)); } }
private Int32Rect convertSelectionToRect(ImageSlice slice) { var r = new Int32Rect( Convert.ToInt32(Canvas.GetLeft(selectionBox) * slice.xSize / image.Width), Convert.ToInt32(Canvas.GetTop(selectionBox) * slice.ySize / image.Height), Convert.ToInt32(selectionBox.Width * slice.xSize / image.Width), Convert.ToInt32(selectionBox.Height * slice.ySize / image.Height) ); if (CheckedResize) { r.Width = Convert.ToInt32(r.Width * slice.selection.Width / slice.xSize); r.Height = Convert.ToInt32(r.Height * slice.selection.Height / slice.ySize); r.X = Convert.ToInt32(slice.selection.X + r.Width); r.Y = Convert.ToInt32(slice.selection.Y + r.Height); } return(r); }
private void statistics(ImageSlice slice) { if (selectionBox.Width > 0 && selectionBox.Height > 0) { var r = convertSelectionToRect(slice); var stats = slice.GetStatistics(r, _numSlice); var dim = slice.GetDimensions(r); avgImg.Text = (Math.Truncate(stats.Item1 * 1000) / 1000).ToString(); stdImg.Text = (Math.Truncate(stats.Item2 * 1000) / 1000).ToString(); noImg.Text = stats.Item3.ToString(); xSize.Text = (Math.Truncate(dim.Item1 * 100.0) / 100.0).ToString() + " " + slice.realUnit; ySize.Text = (Math.Truncate(dim.Item2 * 100.0) / 100.0).ToString() + " " + slice.realUnit; zSize.Text = dim.Item3.ToString() + " " + slice.realUnit; } }
public static ImageSlice operator /(ImageSlice c1, ImageSlice c2) { ImageSlice c = ObjectCopier.Clone <ImageSlice>(c1); c.sliceFileName = "(" + c1.sliceFileName + "/" + c2.sliceFileName + ")"; var tmp = c.minIntensity; c.minIntensity = c.maxIntensity; c.maxIntensity = tmp; for (int i = 0; i < c.xSize; i++) { for (int j = 0; j < c.ySize; j++) { for (int k = 0; k < c.zSize; k++) { if (c2.sliceData[i, j, k] == 0) { c.sliceData[i, j, k] = 0; continue; } c.sliceData[i, j, k] = (c.sliceData[i, j, k] / c2.sliceData[i, j, k]); if (c.sliceData[i, j, k] < c.minIntensity) { c.minIntensity = c.sliceData[i, j, k]; } if (c.sliceData[i, j, k] > c.maxIntensity) { c.maxIntensity = c.sliceData[i, j, k]; } } } } if (c.minIntensity > 0) { c.zeroIntensity = 0.5; } else { c.zeroIntensity = -c.minIntensity / (double)(c.maxIntensity - c.minIntensity); } return(c); }
/// <summary> /// Differentiate two images. /// </summary> /// <param name="c1">image 1</param> /// <param name="c2">image 2</param> /// <returns>image 1 - image 2</returns> public static ImageSlice operator -(ImageSlice c1, ImageSlice c2) { if (c1.xSize != c2.xSize || c1.ySize != c2.ySize || c1.zSize != c2.zSize) { throw new ArgumentOutOfRangeException("operator -", "all sizes have to be the same"); } ImageSlice c = ObjectCopier.Clone <ImageSlice>(c1); c.sliceFileName = "(" + c1.sliceFileName + "-" + c2.sliceFileName + ")"; var tmp = c.minIntensity; c.minIntensity = c.maxIntensity; c.maxIntensity = tmp; for (int i = 0; i < c.xSize; i++) { for (int j = 0; j < c.ySize; j++) { for (int k = 0; k < c.zSize; k++) { c.sliceData[i, j, k] -= c2.sliceData[i, j, k]; if (c.sliceData[i, j, k] < c.minIntensity) { c.minIntensity = c.sliceData[i, j, k]; } if (c.sliceData[i, j, k] > c.maxIntensity) { c.maxIntensity = c.sliceData[i, j, k]; } } } } if (c.minIntensity > 0) { c.zeroIntensity = 0.5; } else { c.zeroIntensity = -c.minIntensity / (double)(c.maxIntensity - c.minIntensity); } return(c); }
private void add_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "TXT files (*.txt)|*.txt|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { // load image from file ImageSlice slice = new ImageSlice(openFileDialog.FileName); _numSlice = 1; // update text field txtNum.Text = _numSlice.ToString(); AddImage(slice, System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName)); // Activate difference button if at least 2 images are added activate_deactivate_Buttons(); } }
private void Grid_MouseUp(object sender, MouseButtonEventArgs e) { // Release the mouse capture and stop tracking it. mouseDown = false; image.ReleaseMouseCapture(); // Hide the drag selection box. //selectionBox.Visibility = Visibility.Collapsed; Point mouseUpPos = e.GetPosition(image); mouseUpPos = transformMouse(mouseUpPos); // // The mouse has been released, calculate all related statistics below // ImageSlice slice = _imageData[fileNameBox.SelectedIndex]; xPos.Text = Math.Round(mouseUpPos.X * slice.xSize / image.Width).ToString(); yPos.Text = Math.Round(mouseUpPos.Y * slice.ySize / image.Height).ToString(); statistics(slice); }