コード例 #1
0
ファイル: SaliencyMap.cs プロジェクト: YHZX2013/exchange_diff
 public SaliencyMap(ArgbImage image, int patchSize, float scale) : this(new LabTiledImage(image, patchSize, scale))
 {
 }
コード例 #2
0
        public override int[][] TransformImage(Hashtable source)
        {
            ArgbImage image = new ArgbImage((int[][])source["image"]);
            int nWidth = (int)source["width"];
            int nHeight = (int)source["height"];
            ScaleInfo si = new ScaleInfo(image.Width, image.Height, nWidth, nHeight);
            int?[][] result = image.Distribute(si); //distribute it across the new image
            if(si.IsShrinking)
                return ArgbImage.Convert(result);
            else if(si.IsZooming)
                return Interpolate(image.Image, result, si.WidthScalingFactor, si.HeightScalingFactor);
            else
                return image.Image;
            //	byte[][] srcImage = (byte[][])source["image"];
            //	int srcWidth = srcImage.Length;
            //	int srcHeight = srcImage[0].Length;
            //	int rsltWidth = (int)source["width"];
            //	int rsltHeight = (int)source["height"];
            //	float srcSize = srcWidth * srcHeight;
            //	float rsltSize = rsltWidth * rsltHeight;
            //	float sWidth = srcWidth;
            //	float sHeight = srcHeight;
            //	float rWidth = rsltWidth;
            //	float rHeight = rsltHeight;
            //	float factor = rsltSize / srcSize;
            //	float wFac = rWidth / sWidth; //width difference factor
            //	float hFac = rHeight / sHeight; //height difference factor

            //	if(factor < 1.0f)
            //	{
            //		//TODO: Improve running time of this code using the
            //		//same method as the other interpolation filters
            //		//shrink the image
            //		//we keep track of the
            //		//we need to shrink it down
            //	  byte[][] result2 = new byte[rsltWidth][];
            //		for(int i = 0; i < result2.Length; i++)
            //		{
            //			var tmp = new byte[rsltHeight];
            //			for(int j = 0; j < tmp.Length; j++)
            //			{
            //				//overlay...its an interesting idea
            //				int r1 = Math.Min(srcWidth - 1,
            //						Math.Max(0, (int)Math.Floor(i / wFac)));
            //				int r2 = Math.Min(srcHeight - 1,
            //						Math.Max(0, (int)Math.Floor(j / hFac)));
            //				tmp[j] = srcImage[r1][r2];
            //			}
            //			result2[i] = tmp;
            //		}
            //		return result2;
            //	}
            //	else if(factor > 1.0f)
            //	{
            //	  byte?[][] rsltImage = new byte?[rsltWidth][];
            //		for(int i = 0; i < rsltImage.Length; i++)
            //			rsltImage[i] = new byte?[rsltHeight];
            //		//setup the image
            //		//zooming works by keeping track of i and j factors that
            //		//grab the factor that is closest to a whole number
            //		float iFactor = 0.0f;
            //		for(int i = 0; i < srcWidth; i++)
            //		{
            //			float jFactor = 0.0f;
            //			for(int j = 0; j < srcHeight; j++)
            //			{
            //				//first map it to the target points in the new image
            //				try
            //				{
            //					rsltImage[(int)Math.Round(iFactor)][(int)Math.Round(jFactor)] = srcImage[i][j];
            //				}
            //				catch(IndexOutOfRangeException)
            //				{
            //					Console.WriteLine("ERROR: iFactor = {0}, jFactor = {1}", iFactor, jFactor);
            //				}
            //				jFactor += hFac;
            //			}
            //			iFactor += wFac;
            //		}
            //		try
            //		{
            //		return Interpolate(srcImage, rsltImage, wFac, hFac);
            //		}
            //		finally
            //		{
            //			srcImage = null;
            //			rsltImage = null; //clean these up
            //		}
            //	}
            //	else
            //		return srcImage;
        }