Mixing Filters Error with Convolution3X3Filter

Apr 10, 2012 at 9:44 AM
Edited Apr 10, 2012 at 9:58 AM

 

Hello,

I am using the google translator, I hope you understand me.

I modified the project for use with Silverlight5 dlls (ex:Windows.System.5.0.5) and create custom effects, mixing all available filters.

The problem is that when I create an effect with all the filters later I run the batchfile and get errors, unless I delete the Convolution3X3Filter.

Do not know why I can not generate the other filters with Convolution3X3Filter. 

 

 I need to apply brightness, contrast, sharpen, B & W,to an image. How I can do this?

Thank you very much.

 

My Configuration in FxDemo.xaml:

 

<pfx:EffectBuilder EffectName="AllEffect">
        <pfx:Contraster FilterName="Contrast"/>
        <pfx:Brighter FilterName="Brightness"/>
        <pfx:Saturator FilterName="Saturation"/>
        <pfx:GrayScaler FilterName="GrayScaler"/>
        <pfx:Clipper FilterName="Clipper"/>
        <pfx:ColorToner FilterName="ColorToner"/>
        <pfx:Inverter FilterName="Inverter"/>
        <pfx:Mixer FilterName="Mixer"/>
        <pfx:Subtractor FilterName="Subtractor"/>
        <pfx:Solarizer FilterName="Solarizer"/>
        <pfx:ThresholdFilter />
        <pfx:WaveWarper FilterName="WaveWarper"/>
        <!--<pfx:Convolution3X3Filter FilterName="Convolution"/>-->
    </pfx:EffectBuilder>

 

 

The errors in bat file execution (without comment Convolution, if i comment these line it's all right with the others filters):

 

C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)>FxGeneratorCmd FxDemo.xaml /wpf:0 /sl:1Compilación iniciada a las 10/04/2012 11:35:51.__________________________________________________Proyecto "C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj" (destinos predeterminados):

Destino PrepareForBuild:    Creando directorio "bin\Silverlight\Release\".    Creando directorio "obj\Debug\".Destino PixelShaderCompile:    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : AllEffect.fx - d3dx9_43.dll : Error - 2147467259 C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(111,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(112,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(113,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(114,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(115,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(116,13): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(146,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(147,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(148,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(149,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(150,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(151,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(152,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(153,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(154,15): warning X3206: implicit truncation of vector type    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(128,11): error X5608: Compiled shader code uses too many arithmetic instruction slots (73). Max. allowed by the target (ps_2_0) is 64.    C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : Compilación terminada del destino "PixelShaderCompile" en el proyecto "FxGenSl.proj" -- ERROR.
Compilación del proyecto "FxGenSl.proj" terminada -- ERROR.
ERROR al compilar.
C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : AllEffect.fx - d3dx9_43.dll : Error -2147467259 C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(111,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(112,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(113,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(114,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(115,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(116,13): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(146,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(147,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(148,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(149,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(150,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(151,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(152,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(153,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(154,15): warning X3206: implicit truncation of vector typeC:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error : C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\AllEffect.fx(128,11): error X5608: Compiled shader code uses too many arithmetic instruction slots (73).Max. allowed by the target (ps_2_0) is 64.C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj : error :    0 Advertencia(s)    1 Errores
Tiempo transcurrido 00:00:01.50
C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)>pause

Presione una tecla para continuar . . .

 

 

Compilation results without Convolution Filter:

 

Compilación iniciada a las 10/04/2012 11:53:04.__________________________________________________

Proyecto "C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\FxGenSl.proj" (destinos predeterminados):

Destino PrepareForBuild:   

Creando directorio "bin\Silverlight\Release\".   

Creando directorio "obj\Debug\".Destino PixelShaderCompile:    AllEffect.fx compiled as AllEffect.ps by d3dx9_43.dll    ClipperEffect.fx compiled as ClipperEffect.ps by d3dx9_43.dll    ColorTonerEffect.fx compiled as ColorTonerEffect.ps by d3dx9_43.dll    ConvolutionEffect.fx compiled as ConvolutionEffect.ps by d3dx9_43.dll    DisplaySettingEffect.fx compiled as DisplaySettingEffect.ps by d3dx9_43.dll    GrayScalerEffect.fx compiled as GrayScalerEffect.ps by d3dx9_43.dll    InverterEffect.fx compiled as InverterEffect.ps by d3dx9_43.dll    LithEffect.fx compiled as LithEffect.ps by d3dx9_43.dll    MixerEffect.fx compiled as MixerEffect.ps by d3dx9_43.dll    SolarizerEffect.fx compiled as SolarizerEffect.ps by d3dx9_43.dll    SubtractorEffect.fx compiled as SubtractorEffect.ps by d3dx9_43.dll    WaveEffect.fx compiled as WaveEffect.ps by d3dx9_43.dll
Destino GenerateTargetFrameworkMonikerAttribute:  Se omitirá el destino "GenerateTargetFrameworkMonikerAttribute" porque todos los archivos de salida están actualizados respecto a los archivos de entrada.

Destino CoreCompile:    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;SILVERLIGHT /reference:"c:\Archivos de programa\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\mscorlib.dll" /reference:"c:\Archivos de programa\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Core.dll" /reference:"c:\Archivos de programa\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.dll" /reference:"c:\Archivos de programa\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0\System.Windows.dll" /debug:pdbonly /optimize+ /out:obj\Debug\FxDemo.Effects.dll /resource:obj\Debug\FxDemo.Effects.g.resources /target:library AllEffect.cs ClipperEffect.cs ColorTonerEffect.cs ConvolutionEffect.cs DisplaySettingEffect.cs GrayScalerEffect.cs InverterEffect.cs LithEffect.cs MixerEffect.cs SolarizerEffect.cs SubtractorEffect.cs WaveEffect.cs "C:\Documents and Settings\user\Configuración Local\Temp\Silverlight,Version=v4.0.AssemblyAttributes.cs"

Destino CopyFilesToOutputDirectory:    Copiando el archivo de "obj\Debug\FxDemo.Effects.dll" en "bin\Silverlight\Release\FxDemo.Effects.dll".    FxGenSl -> C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)\sources\bin\Silverlight\Release\FxDemo.Effects.dll    Copiando el archivo de "obj\Debug\FxDemo.Effects.pdb" en "bin\Silverlight\Release\FxDemo.Effects.pdb".

Compilación correcta.    0 Advertencia(s)    0 Errores

Tiempo transcurrido 00:00:02.71

C:\Documents and Settings\user\Mis documentos\Downloads\PerspectiveFx.bin.x86 (SL5)>pause

Presione una tecla para continuar . . .

Apr 11, 2012 at 8:20 AM

 

Hello again,

I've finally been able to compile the effect with the following filters:

     <pfx:EffectBuilder EffectName="CustomEffect">
         <pfx:Contraster FilterName="Contrast"/>
         <pfx:Brighter FilterName="Brightness"/>
         <pfx:Saturator FilterName="Saturation"/>
         <pfx:Convolution3X3Filter FilterName="Convolution"/>
     </pfx:EffectBuilder>



It is the same as DisplaySettingEffect including Convolution, for Sharpen. The problem now is that I get the image in black and if I set the values ​​of the convolution to 1 for initialize, an image appears distorted and the other filters do not apply (does not change the image by applying other filters in codebehind).

            <Image x:Name="imgTmp" Height="600" Width="700" Canvas.Top="0" Canvas.Left="0" VerticalAlignment="Top" HorizontalAlignment="Left">
                <Image.Effect>
                    <fx:CustomEffect ConvolutionM00="1" ConvolutionM01="1" ConvolutionM02="1"
                                     ConvolutionM10="1" ConvolutionM11="1" ConvolutionM12="1"
                                     ConvolutionM20="1" ConvolutionM21="1" ConvolutionM22="1"/>
                    <!--<fx:DisplaySettingEffect />-->
                </Image.Effect>
            </Image>

Can not use the Convolution with the rest of filters?

Thank you.

 

Apr 19, 2012 at 8:20 AM
Edited Apr 19, 2012 at 8:41 AM

Finally I apply 4 different effects: brightness, sharpen, saturation and contrast. But for separate, together is not possible for me, at the moment. Sharpen with others filters not works.

For sharpen or other convolution filter, if anyone is in the same, the problem was I did not know the combination of the convolution filter to make the image in its default state. This is: 0, 0, 0, 0, 1, 0, 0, 0, 0 - thanks to this help: http://www.codeproject.com/Articles/2008/Image-Processing-for-Dummies-with- C-and-GDI-Part-2

 

                <Image x:Name="imgTmp" Height="600" Width="700" Canvas.Top="0" Canvas.Left="0" VerticalAlignment="Top" HorizontalAlignment="Left">
                    <Image.Effect>
                        <!--<fx:DisplaySettingEffect />-->
                        <fx:CustomEffect ConvolutionM00="0" ConvolutionM01="0" ConvolutionM02="0"
                                         ConvolutionM10="0" ConvolutionM11="1" ConvolutionM12="0"
                                         ConvolutionM20="0" ConvolutionM21="0" ConvolutionM22="0" />
                    </Image.Effect>
                </Image>

And these are other sharpen filters to be applied:

 

 

private void ApplySharpen(bool value)
        {
            //Convolution ARRAY {M00, M01, M02, M10, M11, M12, M20, M21, M22}
            //double[] values = {0, 0, 0, 0, 1, 0, 0, 0, 0}; //DEFAULT
            //double[] values = {0, -1, 0, -1, 5, -1, 0, -1, 0}; //SHARPEN PERSPECTIVE & sharpness of http://www.codeproject.com/Articles/6534/Convolution-of-Bitmaps
            //double[] values = {-1, -1, -1, -1, 16, -1, -1, -1, -1}; //sharpen of http://www.codeproject.com/Articles/6534/Convolution-of-Bitmaps
            //double[] values = {0, -2, 0, -2, 11, -2, 0, -2, 0}; //sharpen of http://www.codeproject.com/Articles/2008/Image-Processing-for-Dummies-with-C-and-GDI-Part-2
            double[] values = { -1, -1, -1, -1, 9, -1, -1, -1, -1 }; //mean removal of http://www.codeproject.com/Articles/2008/Image-Processing-for-Dummies-with-C-and-GDI-Part-2

            if (value)
            {
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM00Property, values[0]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM01Property, values[1]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM02Property, values[2]);

                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM10Property, values[3]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM11Property, values[4]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM12Property, values[5]);

                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM20Property, values[6]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM21Property, values[7]);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM22Property, values[8]);
            }
            else
            {
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM00Property, (double)0);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM01Property, (double)0);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM02Property, (double)0);

                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM10Property, (double)0);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM11Property, (double)1);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM12Property, (double)0);

                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM20Property, (double)0);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM21Property, (double)0);
                imgTmp.Effect.SetValue(CustomEffect.ConvolutionM22Property, (double)0);
            }

            imgTmp.Effect.SetValue(CustomEffect.ConvolutionHorizontalPixelCountProperty, imgTmp.Width);
            imgTmp.Effect.SetValue(CustomEffect.ConvolutionVerticalPixelCountProperty, imgTmp.Height);
        }

 

 

It is sad that this forum is not active, because the library is helpful.

Apr 20, 2012 at 8:16 AM

Finally solved all mixed filters!

In class Convolution3X3Filter of Perspective.PixelShader project, one of the last lines is:          

output.WriteLine("color.rgb = 0.0;");
This means that the filter Convolution always going to take the state's initial RGB image, so the file FxDemo.xaml, Convolution filter has to go first. 

    <pfx:EffectBuilder EffectName="CustomEffect">
        <pfx:Convolution3X3Filter FilterName="Convolution"/>
        <pfx:Brighter FilterName="Brightness"/>
        <pfx:Contraster FilterName="Contrast"/>
        <pfx:Saturator FilterName="Saturation"/>
    </pfx:EffectBuilder>

The end!

 

Coordinator
Jun 14, 2012 at 4:17 PM

Hello,

Sorry, I was very buzy these months. Thanks for your work, I will update the documentation.