Exemple #1
0
        protected override int[] DoFilter(IRasterDataProvider dataProvider, Rectangle aoiRect, int[] aoi, byte[] assistInfo)
        {
            List <int> retAOI = new List <int>(aoi.Length);

            using (IRasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(_argProvider))
            {
                int[] bandNos = new int[] { _midInfraredBandNo, _farInfraredBandNo };
                visitor.VisitPixelWnd(aoiRect, aoi, bandNos, bandNos, _minWndSize, _maxWndSize,
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    return(GetCount(bandValues, wndValues) < _abnormalPixelCount);
                },
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    int count = GetCount(bandValues, wndValues);
                    //
                    if (count >= _abnormalPixelCount)
                    {
                        retAOI.Add(pixelIdx);
                        if (assistInfo != null)
                        {
                            assistInfo[pixelIdx] = 1;
                        }
                    }
                });
            }
            return(retAOI.Count > 0 ? retAOI.ToArray() : null);
        }
Exemple #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            string fname = @"f:\\FY3A_Mersi_2010_06_24_10_00_1000M_L1B_PRJ_Whole.LDF";
            //fname = @"f:\\FY3A_MERSI_2010_06_24_10_00_1000M_L1B - 副本.HDF";
            IRasterDataProvider          prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
            ArgumentProvider             argPrd = new ArgumentProvider(prd, null);
            RasterPixelsVisitor <UInt16> ext    = new RasterPixelsVisitor <ushort>(argPrd);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            ext.VisitPixelWnd(new int[] { 1 }, new int[] { 5 },
                              3, 9, new Func <int, int, ushort[], ushort[][], bool>(IsNeedIncWndSize),
                              new Action <int, int, ushort[], ushort[][]>(Extract));
            sw.Stop();
            Text = sw.ElapsedMilliseconds.ToString();
        }
        private IExtractResult CalcMix(string dblvFile, string ldfFile, double bandZoom, int bandNo, double resultZoom, int[] dblvAOI, float waterNir, float LandNir, double zoom)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("dblvFile", new FilePrdMap(dblvFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("ldfFile", new FilePrdMap(ldfFile, bandZoom, new VaildPra(float.MinValue, float.MaxValue), new int[] { bandNo }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            int minWnd = 3, maxWnd = 3;

            if (vrd == null)
            {
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return(null);
            }
            try
            {
                ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
                RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
                Size size = new Size(vrd.Width, vrd.Height);
                MemPixelFeatureMapper <Int16> result = new MemPixelFeatureMapper <Int16>("0MIX", 1000, size, vrd.CoordEnvelope, vrd.SpatialRef);
                int       dblvBand   = filePrdMap["dblvFile"].StartBand;
                int       ldfBand    = filePrdMap["ldfFile"].StartBand;
                int[]     wndBandNos = new int[] { dblvBand, ldfBand };
                Rectangle aoiRect    = AOIHelper.ComputeAOIRect(dblvAOI, size);
                bool      isEdge     = false;
                using (IRasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap))
                {
                    visitor.VisitPixelWnd(aoiRect, dblvAOI, wndBandNos, wndBandNos, minWnd, maxWnd,
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        return(false);
                    },
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        isEdge = IsEdgeMethod(bandValues, wndValues, 0);
                        if (isEdge)
                        {
                            result.Put(pixelIdx, GetResult(bandValues, wndValues, waterNir, LandNir, zoom));
                        }
                    });
                }
                return(result);
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
            }
        }
        private void GetDBLVAOIIndex(string dblvFile, string cloudFile, List <int> dblvAOI)
        {
            Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();

            filePrdMap.Add("dblvFile", new FilePrdMap(dblvFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            filePrdMap.Add("cloudFile", new FilePrdMap(cloudFile, 1, new VaildPra(float.MinValue, float.MaxValue), new int[] { 1 }));
            ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
            IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            int minWnd = 3, maxWnd = 3;

            if (vrd == null)
            {
                if (filePrdMap != null && filePrdMap.Count > 0)
                {
                    foreach (FilePrdMap value in filePrdMap.Values)
                    {
                        if (value.Prd != null)
                        {
                            value.Prd.Dispose();
                        }
                    }
                }
                return;
            }
            try
            {
                List <int> temp = new List <int>();
                temp.AddRange(dblvAOI);
                dblvAOI.Clear();
                ArgumentProvider ap   = new ArgumentProvider(vrd, null);
                Size             size = new Size(vrd.Width, vrd.Height);
                int       dblvBand    = filePrdMap["dblvFile"].StartBand;
                int       cloudBand   = filePrdMap["cloudFile"].StartBand;
                int[]     tempAOI     = temp.ToArray();
                Rectangle aoiRect     = AOIHelper.ComputeAOIRect(tempAOI, size);
                int[]     wndBandNos  = new int[] { dblvBand, cloudBand };
                bool      isCloudEgde = false;
                using (IRasterPixelsVisitor <float> visitor = new RasterPixelsVisitor <float>(ap))
                {
                    visitor.VisitPixelWnd(aoiRect, tempAOI, wndBandNos, wndBandNos, minWnd, maxWnd,
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        return(false);
                    },
                                          (pixelIdx, crtWndSize, bandValues, wndValues) =>
                    {
                        isCloudEgde = IsCloudEdgeMethod(bandValues, wndValues, 1);
                        if (isCloudEgde)
                        {
                            temp.Remove(pixelIdx);
                        }
                    });
                }
                dblvAOI.AddRange(temp);
                temp = null;
            }
            finally
            {
                if (vrd != null)
                {
                    vrd.Dispose();
                }
            }
        }
        public int[] Filter(IArgumentProvider argProvider, Rectangle aoiRect, int[] aoi)
        {
            List <int> retAOI = new List <int>(aoi.Length);

            using (IRasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(argProvider))
            {
                _width = argProvider.DataProvider.Width;
                //邻域内符合条件的像元个数
                int   preHitedPixelCount = 0;
                int   preWndSize         = 0;
                int[] bandNos            = new int[] { _visBandNo, _nearIfrBandNo, _midIfrBandNo, _farIfrBandNo };
                _visBandIdx      = 0;
                _nearIfrBandIdx  = 1;
                _midIfrBandIdx   = 2;
                _farIfrBandIndex = 3;
                //
                bool isDoubtFir = false;
                //
                int[] hitedIndexes = new int[100 * 100]; //最大窗口100
                visitor.VisitPixelWnd(bandNos, bandNos, _minWndSize, _maxWndSize,
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    if (pixelIdx == 219998)
                    {
                        pixelIdx = 219998;
                    }
                    isDoubtFir = false;
                    //直接判定疑似火点
                    if (bandValues[_midIfrBandIdx] / _bandZoom > (_midInfraredValue_DoubtFir - _dltMidInfraredValue_DoubtFir) &&
                        ((bandValues[_midIfrBandIdx] - bandValues[_farIfrBandIndex]) / _bandZoom) > _midInfrared_farInfrared_DoubtFir)
                    {
                        isDoubtFir = true;
                        retAOI.Add(pixelIdx);
                        return(false);
                    }
                    //
                    if (preWndSize != crtWndSize)
                    {
                        preHitedPixelCount = 0;
                        preWndSize         = crtWndSize;
                    }
                    preHitedPixelCount = GetHitedPixelCount(argProvider, pixelIdx, bandValues, wndValues, hitedIndexes);
                    return(preHitedPixelCount < _maxHitedPixelCount);
                },
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    if (isDoubtFir)
                    {
                        return;
                    }
                    if (preHitedPixelCount < _maxHTmpPixelCount_DoubtFir)
                    {
                        return;
                    }
                    else
                    {
                        float avgMidIfr    = Avg(_midIfrBandIdx, wndValues, preHitedPixelCount, hitedIndexes);
                        float avgMidFarIfr = DiffAvg(_midIfrBandIdx, _farIfrBandIndex, wndValues, preHitedPixelCount, hitedIndexes);
                        bool isOK          = preHitedPixelCount >= _maxHTmpPixelCount_DoubtFir &&
                                             (bandValues[_midIfrBandIdx] / _bandZoom) > (avgMidIfr + _midInfraredAvg_DoubtFir) &&
                                             ((bandValues[_midIfrBandIdx] - bandValues[_farIfrBandIndex]) / _bandZoom) >
                                             (avgMidFarIfr + _midInfraredAvg_DoubtFir)
                        ;
                        if (isOK)
                        {
                            retAOI.Add(pixelIdx);
                        }
                    }
                });
            }
            return(retAOI.Count > 0 ? retAOI.ToArray() : null);
        }
Exemple #6
0
        /// <summary>
        /// 夜间火背景计算
        /// </summary>
        /// <param name="argProvider"></param>
        /// <param name="aoiRect"></param>
        /// <param name="aoi"></param>
        /// <returns></returns>
        public Dictionary <int, PixelFeature> ComputeNight(IArgumentProvider argProvider, Rectangle aoiRect, int[] aoi)
        {
            _width   = argProvider.DataProvider.Width;
            _maxLat  = argProvider.DataProvider.CoordEnvelope.MaxY;
            _res     = argProvider.DataProvider.ResolutionY;
            _isNight = bool.Parse(argProvider.GetArg("IsNight").ToString());
            CreateAndInitFeatures(aoi);
            int tempIndex = 0;

            using (IRasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(argProvider))
            {
                //邻域内符合条件的像元个数
                int   preHitedPixelCount = 0;
                int   preWndSize         = 0;
                int[] bandNos            = new int[] { _midIfrBandNo, _farIfrBandNo };
                _midIfrBandIdx = 0;
                _farIfrBandIdx = 1;
                //
                int[] hitedIndexes = new int[100 * 100]; //最大窗口100
                //
                //by chennan 20140423 处理当当前窗口被恢复成最小窗口时,将晴空像元个数、索引更改回最小窗口状态
                int        preHitedPixelCountSave = 0;
                List <int> hitedIndexesSave       = new List <int>();
                //
                visitor.VisitPixelWnd(aoiRect, aoi, bandNos, bandNos, _minWndSize, _maxWndSize,
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    if (preWndSize != crtWndSize)
                    {
                        preHitedPixelCount = 0;
                        preWndSize         = crtWndSize;
                    }
                    _cloudCount        = 0;
                    preHitedPixelCount = GetNightHitedPixelCount(pixelIdx, bandValues, wndValues, hitedIndexes);
                    //by chennan 20140423 处理当当前窗口被恢复成最小窗口时,将晴空像元个数、索引更改回最小窗口状态
                    //
                    if (crtWndSize == _minWndSize)
                    {
                        preHitedPixelCountSave = preHitedPixelCount;
                        hitedIndexesSave.AddRange(hitedIndexes);
                    }
                    //
                    return(preHitedPixelCount < _maxHitedPixelCount && crtWndSize < _maxWndSize);
                },
                                      (pixelIdx, crtWndSize, bandValues, wndValues) =>
                {
                    if (preHitedPixelCount >= _maxHitedPixelCount)
                    {
                        //by chennan 20140423 处理当当前窗口被恢复成最小窗口时,将晴空像元个数、索引更改回最小窗口状态
                        //
                        if (crtWndSize == _minWndSize)
                        {
                            preHitedPixelCount = preHitedPixelCountSave;
                            hitedIndexes       = hitedIndexesSave.ToArray();
                        }
                        //
                        Compute(preHitedPixelCount, pixelIdx, bandValues, wndValues, hitedIndexes);
                    }
                    else
                    {
                        int row    = pixelIdx / _width;
                        int col    = pixelIdx % _width;
                        int length = crtWndSize / 2;
                        for (int i = row - length; i <= row + length; i++)
                        {
                            if (i < 0)
                            {
                                continue;
                            }
                            for (int j = col - length; j <= col + length; j++)
                            {
                                tempIndex = i * _width + j;
                                if (_featrueIndex.Contains(tempIndex))
                                {
                                    _features[pixelIdx] = _features[tempIndex];
                                }
                            }
                        }
                    }
                    preHitedPixelCountSave = 0;
                    hitedIndexesSave.Clear();
                });
            }
            return(_features);
        }