Exemple #1
0
 private void ButtonShowSagittalNoiseImage_Click(object sender, RoutedEventArgs e)
 {
     if (!ImageInfo.hcFlag)
     {
         //MessageBox.Show("Cannot show image as tumor is not detected.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return;
     }
     short[] img = new short[ImageInfo.Height * ImageInfo.Width];
     if (ImgEvaluation.readShortData(ImageInfo.outputPath + "\\NoiseLabel_Sagittal_" + ImageInfo.Width + "x" + ImageInfo.ImageNumber + ".img", img, 0, ImageInfo.ImageNumber * ImageInfo.Width))
     {
         DisplayShortImage(img, ImageInfo.ImageNumber, ImageInfo.Width);
     }
     img = null;
 }
Exemple #2
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {   // This event is necessary because int he doword event, many things cannot be done, such as button enabling
            // because they must be performed by a different thread.

            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else if (e.Cancelled)
            {
                // Next, handle the case where the user canceled
                // the operation.
                // Note that due to a race condition in
                // the DoWork event handler, the Cancelled
                // flag may not have been set, even though
                // CancelAsync was called.
                measurementProgressBar.Value = 0;

                MeasurementResults.SetAllCancelled();
                DataGridMeasurementResult.ItemsSource = null;
                DataGridMeasurementResult.ItemsSource = MeasurementResults.Result;

                DetectionResults.SetAllNotDetected();
                DataGridDetectionResult.ItemsSource = null;
                DataGridDetectionResult.ItemsSource = DetectionResults.Result;

                string log = "*******************************\r\n";
                log += ImageInfo.measurementTime;
                log += "\r\nMeasurement Cancelled.";
                string path = AppDomain.CurrentDomain.BaseDirectory + "\\QCLog.koning";
                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine(log);
                    sw.WriteLine("\n");
                }
            }
            else
            {
                string log = "*******************************\r\n";
                log += ImageInfo.measurementTime;
                log += "\r\nImage Directory: \r\n" + ImageInfo.inputPath + "\r\n";

                // output results
                if (ImageInfo.phFlag)
                {
                    log += ("Phantom detected, starting on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.phStart]) + "\r\n");
                    DetectionResults.SetDetected("Phantom");
                }
                else
                {
                    log += "Phantom not detected\r\n";
                    DetectionResults.SetNotDetected("Phantom");
                }
                if (ImageInfo.hcFlag)
                {
                    log += ("Contrast structures detected, starting on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.hcStart]) + "\r\n");
                    DetectionResults.SetDetected("Tumor");
                }
                else
                {
                    log += "Contrast structures not detected\r\n";
                    DetectionResults.SetNotDetected("Tumor");
                }
                if (ImageInfo.wtFlag)
                {
                    log += ("Water detected\r\n");
                    DetectionResults.SetDetected("Water");
                }
                else
                {
                    log += "Phantom not detected\r\n";
                    DetectionResults.SetNotDetected("Water");
                }
                if (ImageInfo.clFlag)
                {
                    log += ("Calcifications detected, on " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.clIndex]) + "\r\n");
                    DetectionResults.SetDetected("Calcification");
                }
                else
                {
                    log += "Calcifications not detected";
                    DetectionResults.SetNotDetected("Calcification");
                }


                DataGridDetectionResult.ItemsSource = null;
                DataGridDetectionResult.ItemsSource = DetectionResults.Result;

                // only show measurements if high contrast is detected
                if (ImageInfo.hcFlag)
                {
                    string measurementResult = "";
                    measurementResult += string.Format("\r\nCT Number Accuracy:\r\n     Tumor: {0:F2}\r\n     Water: {1:F2}\r\nField Uniformity: {2:F2}", ImageInfo.hcCTValue, ImageInfo.wtCTValue, ImageInfo.imgUniformity);
                    measurementResult += string.Format("\r\nNoise: {0:F2}\r\nContrast-to-Noise Ratio: {1:F2}", ImageInfo.imgNoise, ImageInfo.lcContrast / ImageInfo.imgNoise);
                    log += measurementResult;

                    MeasurementResults.SetValue("Image Noise:", string.Format("{0:F2}", ImageInfo.imgNoise));
                    MeasurementResults.SetValue("Tumor CT Number:", string.Format("{0:F2}", ImageInfo.hcCTValue));
                    MeasurementResults.SetValue("Water CT Number:", string.Format("{0:F2}", ImageInfo.wtCTValue));
                    MeasurementResults.SetValue("Field Uniformity:", string.Format("{0:F2}", ImageInfo.imgUniformity));
                    MeasurementResults.SetValue("Contrast to Noise Ratio:", string.Format("{0:F2}", ImageInfo.lcContrast / ImageInfo.imgNoise));

                    //// Display the contrastlabel image upon measurement finishing
                    short[] img = new short[ImageInfo.Height * ImageInfo.Width];
                    if (ImgEvaluation.readShortData(ImageInfo.outputPath + "\\ContrastLabel_" + ImageInfo.Width + "x" + ImageInfo.Height + ".img", img, 0, ImageInfo.Height * ImageInfo.Width))
                    {
                        DisplayShortImage(img, ImageInfo.Height, ImageInfo.Width);
                    }
                    img = null;

                    DisplayImage();
                }
                else
                {
                    log += "\r\nMeasurements not performed as high contrast structure not detected.";
                    MeasurementResults.SetAllFailed();
                }

                DataGridMeasurementResult.ItemsSource = null;
                DataGridMeasurementResult.ItemsSource = MeasurementResults.Result;

                string path = AppDomain.CurrentDomain.BaseDirectory + "\\QCLog.koning";

                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine(log);
                    sw.WriteLine("\n");
                }
            }
            measurementProgressBar.Value = 0;
        }
Exemple #3
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            int i = 0;

            short[] img  = new short[ImageInfo.Height * ImageInfo.Width];
            short[] img2 = new short[ImageInfo.Width * ImageInfo.ImageNumber];
            while (!ImageInfo.phFlag && i < ImageInfo.ImageNumber)
            {
                Console.WriteLine("\n" + "Checking: " + Path.GetFileName(ImageInfo.fileNames[i]));
                ImgEvaluation.readDicomData(ImageInfo.fileNames[i], img, ImageInfo.Height * ImageInfo.Width);
                ImgEvaluation.findObject(img, ImageInfo);
                worker.ReportProgress(i + 1);

                if (ImageInfo.phFlag)
                {
                    ImageInfo.phStart = i;
                }
                else
                {
                    i += (int)((1.6) / ImageInfo.pixelSize);
                }

                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
            }

            while (!ImageInfo.hcFlag && i < ImageInfo.ImageNumber)
            {
                Console.WriteLine("\n" + "Checking: " + Path.GetFileName(ImageInfo.fileNames[i]));
                ImgEvaluation.readDicomData(ImageInfo.fileNames[i], img, ImageInfo.Height * ImageInfo.Width);
                ImgEvaluation.findObject(img, ImageInfo);

                // update worker.ProgressPercentage. It's used as slice number here, not percentage
                worker.ReportProgress(i + 1);
                if (ImageInfo.hcFlag)
                {
                    ImageInfo.hcStart = i;
                }
                else
                {
                    i += 3;
                }

                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
            }

            while (!ImageInfo.clFlag && i < ImageInfo.ImageNumber)
            {
                Console.WriteLine("\n" + "Checking: " + Path.GetFileName(ImageInfo.fileNames[i]));
                ImgEvaluation.readDicomData(ImageInfo.fileNames[i], img, ImageInfo.Height * ImageInfo.Width);
                ImgEvaluation.findCalcification(img, ImageInfo);

                // update worker.ProgressPercentage. It's used as slice number here, not percentage
                worker.ReportProgress(i + 1);

                if (ImageInfo.clFlag)
                {
                    ImageInfo.clIndex = i;
                }
                else
                {
                    i++;
                }

                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
            }

            i = ImageInfo.ImageNumber;
            worker.ReportProgress(i);

            if (!ImageInfo.clFlag)
            {
                Console.WriteLine("No calcification detected.");
            }
            else
            {
                Console.WriteLine("\nCalcifications are on: " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.clIndex]));
                ImgEvaluation.maxShortImg(ImageInfo.fileNames, ImageInfo, img);
                ImgEvaluation.writeShortData(ImageInfo.outputPath + "\\CalcificationImg_" + ImageInfo.Width + "x" + ImageInfo.Height + ".img", img, 0, ImageInfo.Height * ImageInfo.Width);

                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }

                i += 20;
                worker.ReportProgress(i);
            }

            if (!ImageInfo.hcFlag)
            {
                Console.WriteLine("No contrast structure detected.");
                return;
            }
            else
            {
                Console.WriteLine("Phantom starts on: " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.phStart]) + "\nContrast structures start on: " + Path.GetFileName(ImageInfo.fileNames[ImageInfo.hcStart]));
                //ImgEvaluation.avgShortNoiseImg(fileNames, ImageInfo, img);
                //ImgEvaluation.writeShortData(ImageInfo.outputPath + "\\noiseImg_" + ImageInfo.Width + "x" + ImageInfo.Height + ".img", img, 0, ImageInfo.Height * ImageInfo.Width);
                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }
                ImgEvaluation.avgShortContrastImg(ImageInfo.fileNames, ImageInfo, img);
                ImgEvaluation.writeShortData(ImageInfo.outputPath + "\\ContrastImg_" + ImageInfo.Width + "x" + ImageInfo.Height + ".img", img, 0, ImageInfo.Height * ImageInfo.Width);
                i += 20;
                worker.ReportProgress(i);

                ImgEvaluation.measureImgQuality(ImageInfo, ImageInfo.fileNames);
                // handle cancellation request
                // cancel work if image found not to be phantom or cancel button pressed
                if (!ImageInfo.isPhantom)
                {
                    backgroundWorker.CancelAsync();
                }
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    return;
                }

                i += 20;
                worker.ReportProgress(i);
            }

            img  = null;
            img2 = null;
            Console.WriteLine("\nApplication is finished.");
        }