/// <summary> This function generates the ROI mask for the entire tile. The mask is
		/// generated for one component. This method is called once for each tile
		/// and component.
		/// 
		/// </summary>
		/// <param name="sb">The root of the subband tree used in the decomposition
		/// 
		/// </param>
		/// <param name="n">component number
		/// 
		/// </param>
		public override void  makeMask(Subband sb, int magbits, int n)
		{
			int nr = nrROIs[n];
			int r;
			int ulx, uly, lrx, lry;
			int tileulx = sb.ulcx;
			int tileuly = sb.ulcy;
			int tilew = sb.w;
			int tileh = sb.h;
			ROI[] ROIs = roi_array; // local copy
			
			ulxs = new int[nr];
			ulys = new int[nr];
			lrxs = new int[nr];
			lrys = new int[nr];
			
			nr = 0;
			
			for (r = ROIs.Length - 1; r >= 0; r--)
			{
				if (ROIs[r].comp == n)
				{
					ulx = ROIs[r].ulx;
					uly = ROIs[r].uly;
					lrx = ROIs[r].w + ulx - 1;
					lry = ROIs[r].h + uly - 1;
					
					if (ulx > (tileulx + tilew - 1) || uly > (tileuly + tileh - 1) || lrx < tileulx || lry < tileuly)
					// no part of ROI in tile
						continue;
					
					// Check bounds
					ulx -= tileulx;
					lrx -= tileulx;
					uly -= tileuly;
					lry -= tileuly;
					
					ulx = (ulx < 0)?0:ulx;
					uly = (uly < 0)?0:uly;
					lrx = (lrx > (tilew - 1))?tilew - 1:lrx;
					lry = (lry > (tileh - 1))?tileh - 1:lry;
					
					ulxs[nr] = ulx;
					ulys[nr] = uly;
					lrxs[nr] = lrx;
					lrys[nr] = lry;
					nr++;
				}
			}
			if (nr == 0)
			{
				roiInTile = false;
			}
			else
			{
				roiInTile = true;
			}
			sMasks[n] = new SubbandRectROIMask(sb, ulxs, ulys, lrxs, lrys, nr);
		}
        /// <summary> The constructor of the SubbandROIMask takes the dimensions of the
        /// subband as parameters. A tree of masks is generated from the subband
        /// sb. Each Subband contains the boundaries of each ROI.
        ///
        /// </summary>
        /// <param name="sb">The subband corresponding to this Subband Mask
        ///
        /// </param>
        /// <param name="ulxs">The upper left x coordinates of the ROIs
        ///
        /// </param>
        /// <param name="ulys">The upper left y coordinates of the ROIs
        ///
        /// </param>
        /// <param name="lrxs">The lower right x coordinates of the ROIs
        ///
        /// </param>
        /// <param name="lrys">The lower right y coordinates of the ROIs
        ///
        /// </param>
        /// <param name="lrys">The lower right y coordinates of the ROIs
        ///
        /// </param>
        /// <param name="nr">Number of ROIs that affect this tile
        ///
        /// </param>
        public SubbandRectROIMask(Subband sb, int[] ulxs, int[] ulys, int[] lrxs, int[] lrys, int nr) : base(sb.ulx, sb.uly, sb.w, sb.h)
        {
            this.ulxs = ulxs;
            this.ulys = ulys;
            this.lrxs = lrxs;
            this.lrys = lrys;
            int r;

            if (sb.isNode)
            {
                isNode = true;
                // determine odd/even - high/low filters
                int horEvenLow = sb.ulcx % 2;
                int verEvenLow = sb.ulcy % 2;

                // Get filter support lengths
                WaveletFilter hFilter = sb.HorWFilter;
                WaveletFilter vFilter = sb.VerWFilter;
                int           hlnSup  = hFilter.SynLowNegSupport;
                int           hhnSup  = hFilter.SynHighNegSupport;
                int           hlpSup  = hFilter.SynLowPosSupport;
                int           hhpSup  = hFilter.SynHighPosSupport;
                int           vlnSup  = vFilter.SynLowNegSupport;
                int           vhnSup  = vFilter.SynHighNegSupport;
                int           vlpSup  = vFilter.SynLowPosSupport;
                int           vhpSup  = vFilter.SynHighPosSupport;

                // Generate arrays for children
                int   x, y;
                int[] lulxs = new int[nr];
                int[] lulys = new int[nr];
                int[] llrxs = new int[nr];
                int[] llrys = new int[nr];
                int[] hulxs = new int[nr];
                int[] hulys = new int[nr];
                int[] hlrxs = new int[nr];
                int[] hlrys = new int[nr];
                for (r = nr - 1; r >= 0; r--)
                {
                    // For all ROI calculate ...
                    // Upper left x for all children
                    x = ulxs[r];
                    if (horEvenLow == 0)
                    {
                        lulxs[r] = (x + 1 - hlnSup) / 2;
                        hulxs[r] = (x - hhnSup) / 2;
                    }
                    else
                    {
                        lulxs[r] = (x - hlnSup) / 2;
                        hulxs[r] = (x + 1 - hhnSup) / 2;
                    }
                    // Upper left y for all children
                    y = ulys[r];
                    if (verEvenLow == 0)
                    {
                        lulys[r] = (y + 1 - vlnSup) / 2;
                        hulys[r] = (y - vhnSup) / 2;
                    }
                    else
                    {
                        lulys[r] = (y - vlnSup) / 2;
                        hulys[r] = (y + 1 - vhnSup) / 2;
                    }
                    // lower right x for all children
                    x = lrxs[r];
                    if (horEvenLow == 0)
                    {
                        llrxs[r] = (x + hlpSup) / 2;
                        hlrxs[r] = (x - 1 + hhpSup) / 2;
                    }
                    else
                    {
                        llrxs[r] = (x - 1 + hlpSup) / 2;
                        hlrxs[r] = (x + hhpSup) / 2;
                    }
                    // lower right y for all children
                    y = lrys[r];
                    if (verEvenLow == 0)
                    {
                        llrys[r] = (y + vlpSup) / 2;
                        hlrys[r] = (y - 1 + vhpSup) / 2;
                    }
                    else
                    {
                        llrys[r] = (y - 1 + vlpSup) / 2;
                        hlrys[r] = (y + vhpSup) / 2;
                    }
                }
                // Create children
                hh = new SubbandRectROIMask(sb.HH, hulxs, hulys, hlrxs, hlrys, nr);
                lh = new SubbandRectROIMask(sb.LH, lulxs, hulys, llrxs, hlrys, nr);
                hl = new SubbandRectROIMask(sb.HL, hulxs, lulys, hlrxs, llrys, nr);
                ll = new SubbandRectROIMask(sb.LL, lulxs, lulys, llrxs, llrys, nr);
            }
        }
        /// <summary> This function generates the ROI mask for the entire tile. The mask is
        /// generated for one component. This method is called once for each tile
        /// and component.
        ///
        /// </summary>
        /// <param name="sb">The root of the subband tree used in the decomposition
        ///
        /// </param>
        /// <param name="n">component number
        ///
        /// </param>
        public override void  makeMask(Subband sb, int magbits, int n)
        {
            int nr = nrROIs[n];
            int r;
            int ulx, uly, lrx, lry;
            int tileulx = sb.ulcx;
            int tileuly = sb.ulcy;
            int tilew   = sb.w;
            int tileh   = sb.h;

            ROI[] ROIs = roi_array;             // local copy

            ulxs = new int[nr];
            ulys = new int[nr];
            lrxs = new int[nr];
            lrys = new int[nr];

            nr = 0;

            for (r = ROIs.Length - 1; r >= 0; r--)
            {
                if (ROIs[r].comp == n)
                {
                    ulx = ROIs[r].ulx;
                    uly = ROIs[r].uly;
                    lrx = ROIs[r].w + ulx - 1;
                    lry = ROIs[r].h + uly - 1;

                    if (ulx > (tileulx + tilew - 1) || uly > (tileuly + tileh - 1) || lrx < tileulx || lry < tileuly)
                    {
                        // no part of ROI in tile
                        continue;
                    }

                    // Check bounds
                    ulx -= tileulx;
                    lrx -= tileulx;
                    uly -= tileuly;
                    lry -= tileuly;

                    ulx = (ulx < 0)?0:ulx;
                    uly = (uly < 0)?0:uly;
                    lrx = (lrx > (tilew - 1))?tilew - 1:lrx;
                    lry = (lry > (tileh - 1))?tileh - 1:lry;

                    ulxs[nr] = ulx;
                    ulys[nr] = uly;
                    lrxs[nr] = lrx;
                    lrys[nr] = lry;
                    nr++;
                }
            }
            if (nr == 0)
            {
                roiInTile = false;
            }
            else
            {
                roiInTile = true;
            }
            sMasks[n] = new SubbandRectROIMask(sb, ulxs, ulys, lrxs, lrys, nr);
        }
Esempio n. 4
0
		/// <summary> The constructor of the SubbandROIMask takes the dimensions of the
		/// subband as parameters. A tree of masks is generated from the subband
		/// sb. Each Subband contains the boundaries of each ROI.
		/// 
		/// </summary>
		/// <param name="sb">The subband corresponding to this Subband Mask
		/// 
		/// </param>
		/// <param name="ulxs">The upper left x coordinates of the ROIs
		/// 
		/// </param>
		/// <param name="ulys">The upper left y coordinates of the ROIs
		/// 
		/// </param>
		/// <param name="lrxs">The lower right x coordinates of the ROIs
		/// 
		/// </param>
		/// <param name="lrys">The lower right y coordinates of the ROIs
		/// 
		/// </param>
		/// <param name="lrys">The lower right y coordinates of the ROIs
		/// 
		/// </param>
		/// <param name="nr">Number of ROIs that affect this tile
		/// 
		/// </param>
		public SubbandRectROIMask(Subband sb, int[] ulxs, int[] ulys, int[] lrxs, int[] lrys, int nr):base(sb.ulx, sb.uly, sb.w, sb.h)
		{
			this.ulxs = ulxs;
			this.ulys = ulys;
			this.lrxs = lrxs;
			this.lrys = lrys;
			int r;
			
			if (sb.isNode)
			{
				isNode = true;
				// determine odd/even - high/low filters
				int horEvenLow = sb.ulcx % 2;
				int verEvenLow = sb.ulcy % 2;
				
				// Get filter support lengths
				WaveletFilter hFilter = sb.HorWFilter;
				WaveletFilter vFilter = sb.VerWFilter;
				int hlnSup = hFilter.SynLowNegSupport;
				int hhnSup = hFilter.SynHighNegSupport;
				int hlpSup = hFilter.SynLowPosSupport;
				int hhpSup = hFilter.SynHighPosSupport;
				int vlnSup = vFilter.SynLowNegSupport;
				int vhnSup = vFilter.SynHighNegSupport;
				int vlpSup = vFilter.SynLowPosSupport;
				int vhpSup = vFilter.SynHighPosSupport;
				
				// Generate arrays for children
				int x, y;
				int[] lulxs = new int[nr];
				int[] lulys = new int[nr];
				int[] llrxs = new int[nr];
				int[] llrys = new int[nr];
				int[] hulxs = new int[nr];
				int[] hulys = new int[nr];
				int[] hlrxs = new int[nr];
				int[] hlrys = new int[nr];
				for (r = nr - 1; r >= 0; r--)
				{
					// For all ROI calculate ...
					// Upper left x for all children
					x = ulxs[r];
					if (horEvenLow == 0)
					{
						lulxs[r] = (x + 1 - hlnSup) / 2;
						hulxs[r] = (x - hhnSup) / 2;
					}
					else
					{
						lulxs[r] = (x - hlnSup) / 2;
						hulxs[r] = (x + 1 - hhnSup) / 2;
					}
					// Upper left y for all children
					y = ulys[r];
					if (verEvenLow == 0)
					{
						lulys[r] = (y + 1 - vlnSup) / 2;
						hulys[r] = (y - vhnSup) / 2;
					}
					else
					{
						lulys[r] = (y - vlnSup) / 2;
						hulys[r] = (y + 1 - vhnSup) / 2;
					}
					// lower right x for all children
					x = lrxs[r];
					if (horEvenLow == 0)
					{
						llrxs[r] = (x + hlpSup) / 2;
						hlrxs[r] = (x - 1 + hhpSup) / 2;
					}
					else
					{
						llrxs[r] = (x - 1 + hlpSup) / 2;
						hlrxs[r] = (x + hhpSup) / 2;
					}
					// lower right y for all children
					y = lrys[r];
					if (verEvenLow == 0)
					{
						llrys[r] = (y + vlpSup) / 2;
						hlrys[r] = (y - 1 + vhpSup) / 2;
					}
					else
					{
						llrys[r] = (y - 1 + vlpSup) / 2;
						hlrys[r] = (y + vhpSup) / 2;
					}
				}
				// Create children
				hh = new SubbandRectROIMask(sb.HH, hulxs, hulys, hlrxs, hlrys, nr);
				lh = new SubbandRectROIMask(sb.LH, lulxs, hulys, llrxs, hlrys, nr);
				hl = new SubbandRectROIMask(sb.HL, hulxs, lulys, hlrxs, llrys, nr);
				ll = new SubbandRectROIMask(sb.LL, lulxs, lulys, llrxs, llrys, nr);
			}
		}