/// <summary> Creates a ROIScaler object. The Quantizer is the source of data to
        /// scale.
        ///
        /// <p>The ROI Scaler creates a ROIMaskGenerator depending on what ROI
        /// information is in the ParameterList. If only rectangular ROI are used,
        /// the fast mask generator for rectangular ROI can be used.</p>
        ///
        /// </summary>
        /// <param name="src">The source of data to scale
        ///
        /// </param>
        /// <param name="pl">The parameter list (or options).
        ///
        /// </param>
        /// <param name="encSpec">The encoder specifications for addition of roi specs
        ///
        /// </param>
        /// <exception cref="IllegalArgumentException">If an error occurs while parsing
        /// the options in 'pl'
        ///
        /// </exception>
        public static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec)
        {
            System.Collections.ArrayList roiVector = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            ROIMaskGenerator             maskGen   = null;

            // Check parameters
            pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));

            // Get parameters and check if there are and ROIs specified
            System.String roiopt = pl.getParameter("Rroi");
            if (roiopt == null)
            {
                // No ROIs specified! Create ROIScaler with no mask generator
                return(new ROIScaler(src, null, false, -1, false, encSpec));
            }

            // Check if the lowest resolution levels should belong to the ROI
            int sLev = pl.getIntParameter("Rstart_level");

            // Check if the ROIs are block-aligned
            bool useBlockAligned = pl.getBooleanParameter("Ralign");

            // Check if generic mask generation is specified
            bool onlyRect = !pl.getBooleanParameter("Rno_rect");

            // Parse the ROIs
            parseROIs(roiopt, src.NumComps, roiVector);
            ROI[] roiArray = new ROI[roiVector.Count];
            roiVector.CopyTo(roiArray);

            // If onlyRect has been forced, check if there are any non-rectangular
            // ROIs specified.  Currently, only the presence of circular ROIs will
            // make this false
            if (onlyRect)
            {
                for (int i = roiArray.Length - 1; i >= 0; i--)
                {
                    if (!roiArray[i].rect)
                    {
                        onlyRect = false;
                        break;
                    }
                }
            }

            if (onlyRect)
            {
                // It's possible to use the fast ROI mask generation when only
                // rectangular ROIs are specified.
                maskGen = new RectROIMaskGenerator(roiArray, src.NumComps);
            }
            else
            {
                // It's necessary to use the generic mask generation
                maskGen = new ArbROIMaskGenerator(roiArray, src.NumComps, src);
            }
            return(new ROIScaler(src, maskGen, true, sLev, useBlockAligned, encSpec));
        }
		/// <summary> The constructor of the mask generator. The constructor is called with
		/// the ROI data. This data is stored in arrays that are used to generate
		/// the SubbandRectROIMask trees for each component.
		/// 
		/// </summary>
		/// <param name="ROIs">The ROI info.
		/// 
		/// </param>
		/// <param name="maxShift">The flag indicating use of Maxshift method.
		/// 
		/// </param>
		/// <param name="nrc">number of components.
		/// 
		/// </param>
		public RectROIMaskGenerator(ROI[] ROIs, int nrc):base(ROIs, nrc)
		{
			int nr = ROIs.Length;
			int r; // c removed
			nrROIs = new int[nrc];
			sMasks = new SubbandRectROIMask[nrc];
			
			// Count number of ROIs per component
			for (r = nr - 1; r >= 0; r--)
			{
				nrROIs[ROIs[r].comp]++;
			}
		}
Example #3
0
		/// <summary> The constructor of the arbitrary mask generator
		/// 
		/// </summary>
		/// <param name="rois">The ROI info.
		/// 
		/// </param>
		/// <param name="nrc">The number of components
		/// 
		/// </param>
		/// <param name="src">The quantizer module
		/// 
		/// </param>
		public ArbROIMaskGenerator(ROI[] rois, int nrc, Quantizer src):base(rois, nrc)
		{
			roiMask = new int[nrc][];
			this.src = src;
		}
Example #4
0
		/// <summary> This function parses the values given for the ROIs with the argument
		/// -Rroi. Currently only circular and rectangular ROIs are supported.
		/// 
		/// <p>A rectangular ROI is indicated by a 'R' followed the coordinates for
		/// the upper left corner of the ROI and then its width and height.</p>
		/// 
		/// <p>A circular ROI is indicated by a 'C' followed by the coordinates of
		/// the circle center and then the radius.</p>
		/// 
		/// <p>Before the R and C values, the component that are affected by the
		/// ROI are indicated.</p>
		/// 
		/// </summary>
		/// <param name="roiopt">The info on the ROIs
		/// 
		/// </param>
		/// <param name="nc">number of components
		/// 
		/// </param>
		/// <param name="roiVector">The vcector containing the ROI parsed from the cmd line
		/// 
		/// </param>
		/// <returns> The ROIs specified in roiopt
		/// 
		/// </returns>
		protected internal static System.Collections.ArrayList parseROIs(System.String roiopt, int nc, System.Collections.ArrayList roiVector)
		{
			//ROI[] ROIs;
			ROI roi;
			SupportClass.Tokenizer stok;
			//char tok;
			int nrOfROIs = 0;
			//char c;
			int ulx, uly, w, h, x, y, rad; // comp removed
			bool[] roiInComp = null;
			
			stok = new SupportClass.Tokenizer(roiopt);
			
			System.String word;
			while (stok.HasMoreTokens())
			{
				word = stok.NextToken();
				
				switch (word[0])
				{
					
					case 'c':  // Components specification
						roiInComp = ModuleSpec.parseIdx(word, nc);
						break;
					
					case 'R':  // Rectangular ROI to be read
						nrOfROIs++;
						try
						{
							word = stok.NextToken();
							ulx = (System.Int32.Parse(word));
							word = stok.NextToken();
							uly = (System.Int32.Parse(word));
							word = stok.NextToken();
							w = (System.Int32.Parse(word));
							word = stok.NextToken();
							h = (System.Int32.Parse(word));
						}
						catch (System.FormatException)
						{
							throw new System.ArgumentException("Bad parameter for " + "'-Rroi R' option : " + word);
						}
						catch (System.ArgumentOutOfRangeException)
						{
							throw new System.ArgumentException("Wrong number of " + "parameters for  " + "h'-Rroi R' option.");
						}
						
						// If the ROI is component-specific, check which comps.
						if (roiInComp != null)
							for (int i = 0; i < nc; i++)
							{
								if (roiInComp[i])
								{
									roi = new ROI(i, ulx, uly, w, h);
									roiVector.Add(roi);
								}
							}
						else
						{
							// Otherwise add ROI for all components
							for (int i = 0; i < nc; i++)
							{
								roi = new ROI(i, ulx, uly, w, h);
								roiVector.Add(roi);
							}
						}
						break;
					
					case 'C':  // Circular ROI to be read
						nrOfROIs++;
						
						try
						{
							word = stok.NextToken();
							x = (System.Int32.Parse(word));
							word = stok.NextToken();
							y = (System.Int32.Parse(word));
							word = stok.NextToken();
							rad = (System.Int32.Parse(word));
						}
						catch (System.FormatException)
						{
							throw new System.ArgumentException("Bad parameter for " + "'-Rroi C' option : " + word);
						}
						catch (System.ArgumentOutOfRangeException)
						{
							throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi C' option.");
						}
						
						// If the ROI is component-specific, check which comps.
						if (roiInComp != null)
							for (int i = 0; i < nc; i++)
							{
								if (roiInComp[i])
								{
									roi = new ROI(i, x, y, rad);
									roiVector.Add(roi);
								}
							}
						else
						{
							// Otherwise add ROI for all components
							for (int i = 0; i < nc; i++)
							{
								roi = new ROI(i, x, y, rad);
								roiVector.Add(roi);
							}
						}
						break;
					
					case 'A':  // ROI wth arbitrary shape
						nrOfROIs++;
						
						System.String filename;
						ImgReaderPGM maskPGM = null;
						
						try
						{
							filename = stok.NextToken();
						}
						catch (System.ArgumentOutOfRangeException)
						{
							throw new System.ArgumentException("Wrong number of " + "parameters for " + "'-Rroi A' option.");
						}
						try
						{
							maskPGM = new ImgReaderPGM(filename);
						}
						catch (System.IO.IOException)
						{
							throw new System.ApplicationException("Cannot read PGM file with ROI");
						}
						
						// If the ROI is component-specific, check which comps.
						if (roiInComp != null)
							for (int i = 0; i < nc; i++)
							{
								if (roiInComp[i])
								{
									roi = new ROI(i, maskPGM);
									roiVector.Add(roi);
								}
							}
						else
						{
							// Otherwise add ROI for all components
							for (int i = 0; i < nc; i++)
							{
								roi = new ROI(i, maskPGM);
								roiVector.Add(roi);
							}
						}
						break;
					
					default: 
						throw new System.ApplicationException("Bad parameters for ROI nr " + roiVector.Count);
					
				}
			}
			
			return roiVector;
		}
Example #5
0
		/// <summary> Creates a ROIScaler object. The Quantizer is the source of data to
		/// scale.
		/// 
		/// <p>The ROI Scaler creates a ROIMaskGenerator depending on what ROI
		/// information is in the ParameterList. If only rectangular ROI are used,
		/// the fast mask generator for rectangular ROI can be used.</p>
		/// 
		/// </summary>
		/// <param name="src">The source of data to scale
		/// 
		/// </param>
		/// <param name="pl">The parameter list (or options).
		/// 
		/// </param>
		/// <param name="encSpec">The encoder specifications for addition of roi specs
		/// 
		/// </param>
		/// <exception cref="IllegalArgumentException">If an error occurs while parsing
		/// the options in 'pl'
		/// 
		/// </exception>
		public static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec)
		{
			System.Collections.ArrayList roiVector = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			ROIMaskGenerator maskGen = null;
			
			// Check parameters
			pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));
			
			// Get parameters and check if there are and ROIs specified 
			System.String roiopt = pl.getParameter("Rroi");
			if (roiopt == null)
			{
				// No ROIs specified! Create ROIScaler with no mask generator
				return new ROIScaler(src, null, false, - 1, false, encSpec);
			}
			
			// Check if the lowest resolution levels should belong to the ROI 
			int sLev = pl.getIntParameter("Rstart_level");
			
			// Check if the ROIs are block-aligned
			bool useBlockAligned = pl.getBooleanParameter("Ralign");
			
			// Check if generic mask generation is specified 
			bool onlyRect = !pl.getBooleanParameter("Rno_rect");
			
			// Parse the ROIs
			parseROIs(roiopt, src.NumComps, roiVector);
			ROI[] roiArray = new ROI[roiVector.Count];
			roiVector.CopyTo(roiArray);
			
			// If onlyRect has been forced, check if there are any non-rectangular
			// ROIs specified.  Currently, only the presence of circular ROIs will
			// make this false
			if (onlyRect)
			{
				for (int i = roiArray.Length - 1; i >= 0; i--)
					if (!roiArray[i].rect)
					{
						onlyRect = false;
						break;
					}
			}
			
			if (onlyRect)
			{
				// It's possible to use the fast ROI mask generation when only
				// rectangular ROIs are specified.
				maskGen = new RectROIMaskGenerator(roiArray, src.NumComps);
			}
			else
			{
				// It's necessary to use the generic mask generation
				maskGen = new ArbROIMaskGenerator(roiArray, src.NumComps, src);
			}
			return new ROIScaler(src, maskGen, true, sLev, useBlockAligned, encSpec);
		}
Example #6
0
		/// <summary> The constructor of the mask generator
		/// 
		/// </summary>
		/// <param name="rois">The ROIs in the image
		/// 
		/// </param>
		/// <param name="nrc">The number of components
		/// </param>
		public ROIMaskGenerator(ROI[] rois, int nrc)
		{
			this.roi_array = rois;
			this.nrc = nrc;
			tileMaskMade = new bool[nrc];
		}