Ejemplo n.º 1
0
        /// <summary>
        /// Performs the Canny edge detection algorithm given a color image.
        /// The output is a texture that stores edge gradients in Red-Green
        ///     and edge strengths in Blue.
        /// Note that edge strength is equal to the length of the edge gradient.
        /// </summary>
        public static void FullCannyEdgeFilter(
            Texture inputTex, RenderTexture outputTex,
            GaussianBlurQuality blurQuality, GreyscaleTypes greyscaleMode, EdgeFilters edgeFilter,
            float weakEdgeThreshold, float strongEdgeThreshold,
            TextureWrapMode samplingWrapMode = TextureWrapMode.Clamp)
        {
            RenderTexture out_gaussian = RenderTexture.GetTemporary(
                inputTex.width, inputTex.height, 0,
                RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear),
                          out_greyscale = RenderTexture.GetTemporary(
                outputTex.width, outputTex.height, 0,
                RenderTextureFormat.RInt, RenderTextureReadWrite.Linear),
                          out_edgeDetect = RenderTexture.GetTemporary(
                outputTex.width, outputTex.height, 0,
                RenderTextureFormat.RGFloat, RenderTextureReadWrite.Linear);

            out_gaussian.filterMode   = FilterMode.Point;
            out_gaussian.wrapMode     = samplingWrapMode;
            out_greyscale.filterMode  = FilterMode.Point;
            out_greyscale.wrapMode    = samplingWrapMode;
            out_edgeDetect.filterMode = FilterMode.Point;
            out_edgeDetect.wrapMode   = samplingWrapMode;

            Blur(blurQuality, inputTex, out_gaussian, samplingWrapMode);
            Greyscale(greyscaleMode, out_gaussian, out_greyscale);
            EdgeFilter(edgeFilter, out_greyscale, out_edgeDetect, samplingWrapMode);
            CannyEdgeFilter(out_edgeDetect, outputTex,
                            weakEdgeThreshold, strongEdgeThreshold,
                            samplingWrapMode);

            RenderTexture.ReleaseTemporary(out_edgeDetect);
            RenderTexture.ReleaseTemporary(out_greyscale);
            RenderTexture.ReleaseTemporary(out_gaussian);
        }
Ejemplo n.º 2
0
        public static RenderTexture Greyscale(GreyscaleTypes type, Texture inputTex,
                                              RenderTextureFormat outFormat = RenderTextureFormat.RInt)
        {
            var outTex = new RenderTexture(inputTex.width, inputTex.height, 0, outFormat,
                                           RenderTextureReadWrite.Linear);

            outTex.filterMode = FilterMode.Point;

            Greyscale(type, inputTex, outTex);

            return(outTex);
        }
Ejemplo n.º 3
0
        public static void Greyscale(GreyscaleTypes type, Texture input, RenderTexture output)
        {
            //Get the correct pass to use in the uber filter shader.
            Passes pass;

            switch (type)
            {
            case GreyscaleTypes.PreserveLuminance:
                pass = Passes.LuminanceGreyscale;
                break;

            default: throw new NotImplementedException(type.ToString());
            }

            //Do the filter.
            var mat = UberFilterMat;

            Graphics.Blit(input, output, mat, (int)pass);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs the Canny edge detection algorithm given a color image.
        /// </summary>
        public static RenderTexture FullCannyEdgeFilter(
            Texture inputTex,
            GaussianBlurQuality blurQuality, GreyscaleTypes greyscaleMode, EdgeFilters edgeFilter,
            float weakEdgeThreshold, float strongEdgeThreshold,
            TextureWrapMode samplingWrapMode = TextureWrapMode.Clamp,
            RenderTextureFormat outFormat    = RenderTextureFormat.ARGBFloat)
        {
            var outTex = new RenderTexture(inputTex.width, inputTex.height, 0,
                                           outFormat, RenderTextureReadWrite.Linear);

            outTex.filterMode = FilterMode.Point;
            outTex.wrapMode   = samplingWrapMode;

            FullCannyEdgeFilter(inputTex, outTex,
                                blurQuality, greyscaleMode, edgeFilter,
                                weakEdgeThreshold, strongEdgeThreshold,
                                samplingWrapMode);

            return(outTex);
        }