Exemple #1
0
        private int[] calculate16bitHisogram(TifFileInfo fi, int C, int imageN = -1)
        {
            FrameCalculator FC    = new FrameCalculator();
            int             frame = FC.FrameC(fi, C);

            if (imageN != -1)
            {
                frame = imageN;
            }

            int step = 101 - fi.spotSensitivity[C];

            int[] res = new int[Convert.ToInt32(ushort.MaxValue / step) + 1];

            //calculate histogram
            foreach (ushort[] row in fi.image16bitFilter[frame])
            {
                foreach (ushort val in row)
                {
                    res[Convert.ToInt32(val / step)]++;
                }
            }

            return(res);
        }
Exemple #2
0
        private void calculate8bitHistogram(float[] h, TifFileInfo fi, int width, int height)
        {
            FrameCalculator FC    = new FrameCalculator();
            int             frame = FC.FrameC(fi, fi.cValue);

            if (fi.sumHistogramChecked[fi.cValue] == false)
            {
                //histogram of current frame
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        h[fi.image8bitFilter[frame][y][x]]++;
                    }
                }
            }
            else
            {
                //histogram of all images
                int[]     input = new int[(int)(fi.imageCount / fi.sizeC)];
                float[][] hList = new float[input.Length][];
                //check wich frames are from selected color
                for (int i = 0, val = fi.cValue; i < input.Length; i++, val += fi.sizeC)
                {
                    input[i] = val;
                }
                //calculate histograms for all images
                Parallel.For(0, input.Length, (i) =>
                {
                    float[] h1 = new float[NGRAY];

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            h1[fi.image8bitFilter[input[i]][y][x]]++;
                        }
                    }

                    hList[i] = h1;
                });
                //sum histograms to one
                for (int hInd = 0; hInd < hList.Length; hInd++)
                {
                    for (int i = 0; i < NGRAY; i++)
                    {
                        h[i] += hList[hInd][i];
                    }
                }
            }
        }
        public void calculateHistogramArray(TifFileInfo fi, bool LoadChart)
        {
            TifFileInfo oldFI = IA.TabPages.TabCollections[IA.TabPages.SelectedIndex].tifFI;

            if (fi.image16bit == null & fi.image8bit == null)
            {
                return;
            }
            oldFI = fi;
            FrameCalculator FC    = new FrameCalculator();
            int             frame = FC.Frame(fi);

            if (fi.openedImages < frame)
            {
                return;
            }
            //Chech is array empty and fill it
            if (fi.histogramArray == null)
            {
                PrepareArray(fi);
            }
            //Empty current array
            for (int i = 0; i < fi.histogramArray[fi.cValue].Length; i++)
            {
                fi.histogramArray[fi.cValue][i] = 0;
            }
            //Fill the array
            bool check = false;

            switch (fi.bitsPerPixel)
            {
            case 8:
                check = calculateHistogram8bit(fi, frame);
                break;

            case 16:
                check = calculateHistogram16bit(fi, frame);
                break;
            }
            if (check == false)
            {
                return;
            }
            //Load array to Chart
            if (LoadChart == true)
            {
                loadHistogramArray(fi);
            }
        }
Exemple #4
0
        private void calculate16bitHistogram(float[] h, TifFileInfo fi, int width, int height)
        {
            if (fi.sumHistogramChecked[fi.cValue] == false)
            {
                //histogram of current frame
                FrameCalculator FC    = new FrameCalculator();
                int             frame = FC.FrameC(fi, fi.cValue);

                int   maxVal = ushort.MaxValue + 1;
                int[] lut    = new int[maxVal];
                //convert information to 8 bit
                int step = (int)(calculateMaxIntensity(fi, frame) / 256);
                GlobalStep16Bit = step;
                for (int i = 0, count = 0, val = 0; i < maxVal; i++, count++)
                {
                    if (count >= step)
                    {
                        count = 0;
                        if (val < 255)
                        {
                            val++;
                        }
                    }
                    lut[i] = val;
                }
                //calculate histogram
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        h[lut[fi.image16bitFilter[frame][y][x]]]++;
                    }
                }
            }
            else
            {
                //histogram of all images
                int[]     input = new int[(int)(fi.imageCount / fi.sizeC)];
                float[][] hList = new float[input.Length][];

                //check wich frames are from selected color
                for (int i = 0, val = fi.cValue; i < input.Length; i++, val += fi.sizeC)
                {
                    input[i] = val;
                }
                //Find absolute max intensity
                ushort[] maxVals = new ushort[input.Length];
                Parallel.For(0, input.Length, (i) =>
                {
                    maxVals[i] = calculateMaxIntensity(fi, input[i]);
                });

                ushort max = 0;
                foreach (ushort val in maxVals)
                {
                    if (val > max)
                    {
                        max = val;
                    }
                }

                int   maxVal = ushort.MaxValue + 1;
                int[] lut    = new int[maxVal];
                //convert information to 8 bit
                int step = (int)(max / 256);
                GlobalStep16Bit = step;
                for (int i = 0, count = 0, val = 0; i < maxVal; i++, count++)
                {
                    if (count >= step)
                    {
                        count = 0;
                        if (val < 255)
                        {
                            val++;
                        }
                    }
                    lut[i] = val;
                }
                //calculate histograms for all images
                Parallel.For(0, input.Length, (i) =>
                {
                    float[] h1 = new float[NGRAY];

                    for (int y = 0; y < height; y++)
                    {
                        for (int x = 0; x < width; x++)
                        {
                            h[lut[fi.image16bitFilter[input[i]][y][x]]]++;
                        }
                    }

                    hList[i] = h1;
                });
                //sum histograms to one
                for (int hInd = 0; hInd < hList.Length; hInd++)
                {
                    for (int i = 0; i < NGRAY; i++)
                    {
                        h[i] += hList[hInd][i];
                    }
                }
            }
        }
Exemple #5
0
        private void Kmeans16bit(TifFileInfo fi, int NumberOfColors)
        {
            int count = 0;
            var bgw   = new BackgroundWorker();

            bgw.WorkerReportsProgress = true;
            //Add event for projection here
            bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
            {
                //Check is processed image enabled
                if (fi.image16bitFilter == null)
                {
                    fi.image16bitFilter = fi.image16bit;
                }
                //Calculate active frame
                FrameCalculator FC = new FrameCalculator();
                int frame          = FC.FrameC(fi, fi.cValue);
                //find active image data
                ushort[][] image = fi.image16bitFilter[frame];
                //find first centroids
                findFirstCentroids(image, NumberOfColors);
                for (int i = 0; i < topColours.Length; i++)
                {
                    previousCluster.Add(topColours[i], new Cluster((float)topColours[i]));
                    currentCluster.Add(topColours[i], new Cluster((float)topColours[i]));
                }

                BuildHistogram(fi, frame);

                ((BackgroundWorker)o).ReportProgress(1);

                converged = false;

                while (!converged)
                {
                    Iterate();

                    for (int i = 0, j = 1; j < NumberOfColors; i++, j++)
                    {
                        fi.thresholdValues[fi.cValue][j] = (int)Thresholds[i];
                    }

                    count++;
                    ((BackgroundWorker)o).ReportProgress(1);
                }

                ((BackgroundWorker)o).ReportProgress(0);
            });

            bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
            {
                if (a.ProgressPercentage == 0)
                {
                    fi.available = true;
                    IA.FileBrowser.StatusLabel.Text = "Ready";
                    ClearData();
                    IA.ReloadImages();
                }
                else
                {
                    IA.FileBrowser.StatusLabel.Text = "K-means: " + count.ToString() + " iterations...";
                }
            });
            //Start background worker
            IA.FileBrowser.StatusLabel.Text = "K-means: Building Histogram...";
            //start bgw
            bgw.RunWorkerAsync();
        }