-1

I want to find a entropy for an image using R programming with the help of Asp.Net.I have downloaded and install the statconnDCOM to there default location.i'm using following assembly

using STATCONNECTORCLNTLib;

using StatConnectorCommonLib;

using STATCONNECTORSRVLib;

My C# code is

    static StatConnector rconn;
    static void Main(string[] args)
    {

        try
        {
            //Calculate Statistics in R
            rconn.Init("R");
            rconn.Evaluate("require(indicoio)");
            rconn.Evaluate("require(jpeg)");
            rconn.Evaluate("imgPath<-C:/Users/Sunil/Desktop/apple2.jpg");

            //Read the image into a raster array
            rconn.Evaluate("img<-readJPEG(imgPath, native = FALSE)");

            //convert the array to a data.frame or matrix
            rconn.Evaluate("mystring<-as.data.frame(img)");
            rconn.Evaluate("myfreqs <- mystring / sum(mystring)");

            //vectorize
            rconn.Evaluate("myvec <- as.data.frame(myfreqs)[,2]");

            // H in bit
            double average = (double)rconn.GetSymbol(rconn.Evaluate("-sum(myvec * log2(myvec))"));

            Console.WriteLine("Entropy is: " + average);
            Console.ReadLine();           


        }
        catch(Exception ex)
        {
            Console.WriteLine("Error: " + ex);
            Console.ReadLine();
        }
  • I used static StatConnector rconn=new StatConnector(); to solve the problem but now I'm getting System.Runtime.InteropServices.COMException (0x80040013): Exception from HRESULT: 0x80040013 at StatConnectorCommonLib.IStatConnector.Init(String bstrConnectorName) error – SUNIL UPADHYAY Aug 15 '15 at 15:45

1 Answers1

1

Your rconn object is not instantiated. At the beggining of Main function add:

rconn = new StatConnector();
Daniel Luberda
  • 6,941
  • 1
  • 26
  • 38