Home Image-Pro Automation (Macros, Apps, Reports)

About commands of SendToExcel and HistogramToExcel

Hello,

I have two questions about commands of SendToExcel and HistogramToExcel.

As for the first question,
in Image-Pro Plus 7.0J, I could save statistics data in cnt or hst format file with using Macros.
And in Image-Pro Premier, although I can paste them to Excel, I cannot save them in Excel file with using Macros.

Please tell me how to save them in Excel file with using Macros.


As for the second question,
I did the following two operations and recorded them in a Macro.
However, the Macro had only the code of 2.

1.Display the statistics data of a brightness histogram graph.
2.Paste them to Excel.

Please tell me how to display the statistics data of a brightness histogram graph with using Macros.
(I assume that settings of IP Premier are default settings when users use macros.)


Thanks.

Uemoto
(Temporarily I am using  Mr. Morita's account of Japan Roper for asking this question.)

Best Answer

  • Answer ✓
    Hello Uemoto,

    It's easy to identify the problem when you explain it clearly. So, the issue is the histogram calculations with and without ROI, right? 
    The Histogram panel, by default, shows the histogram of the active ROI. You can switch this option off in the context menu activating the "Ignore ROI" checkbox:



    Here is the macro that calculates standard deviation of Histogram in 4 different ways:
        Public Sub PrintHistogramSampledStdDev4
            'print standard deviation or the Gray image (or first channel of the color image)
            Dim hist As MediaCy.IQL.Operations.McHistogram = ThisApplication.ActiveImage.HistogramSampled
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation
            hist.Mode=hist.Mode Or MediaCy.IQL.Operations.mcHistogramMode.mchmIgnoreAoi'whole image, ignore ROI
            Debug.Print( String.Format("Sampled Histogram Whole Image standard deviation = {0}",hist.StdDev(0)))
            hist.Mode=hist.Mode And (Not MediaCy.IQL.Operations.mcHistogramMode.mchmIgnoreAoi)'use ROI
            Debug.Print( String.Format("Sampled Histogram ROI standard deviation = {0}",hist.StdDev(0)))
            hist = ThisApplication.ActiveImage.Histogram'FULL histogram
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation
            hist.Mode=hist.Mode Or MediaCy.IQL.Operations.mcHistogramMode.mchmIgnoreAoi'whole image, ignore ROI
            Debug.Print( String.Format("FULL Histogram Whole Image standard deviation = {0}",hist.StdDev(0)))
            hist.Mode=hist.Mode And (Not MediaCy.IQL.Operations.mcHistogramMode.mchmIgnoreAoi)'use ROI
            Debug.Print( String.Format("FULL Histogram ROI standard deviation = {0}",hist.StdDev(0)))
        End Sub
    

    Results look like this:

    Sampled Histogram Whole Image standard deviation = 50.2333673885088
    Sampled Histogram ROI standard deviation = 55.5875106226276
    FULL Histogram Whole Image standard deviation = 50.4102732066266
    FULL Histogram ROI standard deviation = 55.7712793655485

    Check the results and pick the one you think is correct.

    Yuri

Answers

  • Hello Uemoto,

    You can export Histogram statistics to Excel using context menu over the stats pane:


    If you activate macro recording and export the stats, you will record a macro that exports the data, that can be used in macros or addin. The macro looks like this:

        Public Function ExportHistStatsToExcel() As SimpleScript
            ExportHistStatsToExcel = New SimpleScript
    
            With Measure.Data.Export.HistogramCommands.HistogramToExcel(ExportHistStatsToExcel)
                .Export = Export.HistogramExportSources.Statistics
                .Run()
            End With
    
        End Function
    
    Other options can be set using the code in this topic: http://forums.mediacy.com/discussion/comment/2760#Comment_2760 

    Let me know if that will work for you.

    You can also get histogram statistics values directly from a macro using ThisApplication.ActiveImage.Histogram:

        Public Sub PrintHistStats
            Dim hist As MediaCy.IQL.Operations.IMcHistogram=ThisApplication.ActiveImage.Histogram
            hist.Interpretation=mcInterpretation.mciMonochrome'set monochrome interpretation
            Debug.Print String.Format("Mean = {0}",hist.Mean(0))
            Debug.Print String.Format("StdDev = {0}",hist.StdDev(0))
        End Sub
    

    or check the following posts on the forum:

    http://forums.mediacy.com/discussion/comment/1145#Comment_1145
    http://forums.mediacy.com/discussion/417/image-histogram/p1

    Yuri
  • Hello Yuri,

    Thank you for your advice.

    As for my first question,
    Does IP Premier have no function that automatically save Excel file with a name with Macros?
    IP Plus 7.0J has a function that automatically save cnt or hst format file with a name with Macros.


    As for my second question,

    >>You can export Histogram statistics to Excel using context menu over the status pane:

    I knew how to "manually" export Histogram statistics to Excel using context menu over the status pane.
    What I wanted to know was how to "automatically" export them to Excel using it over the status pane.

    I could make a Macro which pasted Histogram statistics to Excel.
    But I couldn't make a Macro which showed Mono menu.

    I wanted to show Mono menu and to paste Histogram statistics to Excel with a Macro.
    However, because I only need to get the standard deviation value, the Macro is no longer necessary.


    And please let me ask you for one more question.

    Despite using the same codes, the values ​​outputtted to Excel are different between Sample Tool(VB.net) and Macros(IP Premier).
    The result of the Macros is correct, but the result of the sample tool is incorrect.
    The standard deviation value displayed in the text box is also incorrect.

    Please tell me what is the cause.


    Thanks.

    Uemoto

    Below is the codes of VB.net.

    --------------------------------------------------
        Public Function test3_tsubure() As SimpleScript
            test3_tsubure = New SimpleScript
            Dim image1

            With Automation.Application.RibbonCommands.SelectRibbonTab(test3_tsubure)
                .TabName = "Capture"
                .Run()
            End With

            With Automation.Application.DocumentCommands.ActiveImage(test3_tsubure)
                .Text = "アクティブな画像"
                .Run(image1)
            End With

            With Automation.Application.Gadgets.ImageHistogram(test3_tsubure)
                .CheckState = MediaCy.IQL.Application.McCommand.mcCheckState.Checked
                .Run()
            End With

            With Measure.Data.Export.HistogramCommands.HistogramToExcel(test3_tsubure)
                .Export = Export.HistogramExportSources.Statistics
                .Run()
            End With

        End Function
    --------------------------------------------------
        Public Function test4_tsubure() As SimpleScript

            test4_tsubure = New SimpleScript

            Dim image1

            With Automation.Application.DocumentCommands.ActiveImage(test3_tsubure)
                .Text = "アクティブな画像"
                .Run(image1)
            End With

            Dim hist As MediaCy.IQL.Operations.IMcHistogram = ThisApplication.ActiveImage.Histogram
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation

            TextBox1.Text = String.Format("StdDev = {0}", hist.StdDev(0))
            TextBox2.Text = String.Format(hist.StdDev(0))

        End Function
    --------------------------------------------------

  • Uemoto,

    It's possible to save data to XLS file directly from several controls, for example measurements table. You can just activate recording and check the command that's recorded.

    Regarding the difference in histogram statistics: there are 2 histograms that are available for images ThisApplication.ActiveImage.Histogram  and ThisApplication.ActiveImage.HistogramSampled, the second version is faster  (especially for large images) as it skips some values and frames, the generated values can be slightly different from FULL histogram stats. The second version is used with Histogram control. 

    Yuri

  • Hi Uemoto,

    The ExportToExcel command has FileName and FileOptions to exports directly to XLSX. Ex:
        Public Function Export_To_File() As SimpleScript
            Export_To_File = New SimpleScript
    
            With Measure.Data.ExportCommands.ExportToExcel(Export_To_File)
                .FileName = "C:\test.xlsx"'destination file
                .FileOptions=Export.ExportToFile.FileOptions.Append'file option
                .Visible=False'do not show Excel
    
                .Run("Title", "Table;Table;Table")
            End With
    
        End Function
    
    Most export commands inherited from ExportToExcel and could export to file directly, for other cases you could use ExportToExcel.

    Thanks,
    Nikita.



  • Hello Yuri and Nikita,

    Thank you for your advice.

    >>Regarding the difference in histogram statistics: there are 2 histograms that are available for images ThisApplication.ActiveImage.Histogram  and ThisApplication.ActiveImage.HistogramSampled,

    I just pasted a macro code of IP Premier to VB.net.
    But do you want to mean that I used two kinds of histogram statistics?
    I can not understand it well.


    Anyway,I want to save the value(=3.148701) of the StdDev displayed on Mono menu in another variable.
    Please tell me how to do it.

    Thanks.

    Uemoto


    The following code did not work.
    The value of the StdDev was not correct.

    --------------------------------------------------
        Public Function test4_tsubure() As SimpleScript

            test4_tsubure = New SimpleScript

            Dim image1

            With Automation.Application.DocumentCommands.ActiveImage(test3_tsubure)
                .Text = "アクティブな画像"
                .Run(image1)
            End With

            Dim hist As MediaCy.IQL.Operations.IMcHistogram = ThisApplication.ActiveImage.Histogram
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation

            TextBox1.Text = String.Format("StdDev = {0}", hist.StdDev(0))
            TextBox2.Text = String.Format(hist.StdDev(0))

        End Function
    --------------------------------------------------

  • Hello Uemoto,

    If you want to get the same values as in the Histogram dialog, you should use ThisApplication.ActiveImage.HistogramSampled (instead of ThisApplication.ActiveImage.Histogram).

    You can find more info about sampling in the Automation help, look at IMcHistogram2 properties: SamplingCoverage, SampledFraction:



    If you need FULL histogram, without sampling, use ThisApplication.ActiveImage.Histogram.

    Yuri
  • Hello Yuri and Nikita,

    Thank you for your advice.

    I found a mistake in my program codes and fixed it.
    Then I could paste correct results to Excel with VB.

    But I couldn't save the value of the StdDev displayed on Mono menu in another variable because I didn't know the correct description of the program codes.
    Since detailed description method is not listed in the help of IP Premier, I didn't know how to use ThisApplication.ActiveImage.HistogramSampled.

    The following codes did not work.
    The value of the StdDev was not correct.

    --------------------------------------------------
    Public Function test4_tsubure() As SimpleScript

            test4_tsubure = New SimpleScript

            Dim image1

            With Automation.Application.DocumentCommands.ActiveImage(test4_tsubure)
                .Text = "アクティブな画像"
                .Run(image1)
            End With

            '↓ I fixed IMcHistogram and Histogram to IMcHistogram2 and HistogramSampled.
            Dim hist As MediaCy.IQL.Operations.IMcHistogram2 = ThisApplication.ActiveImage.HistogramSampled
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation

            TextBox1.Text = String.Format("StdDev = {0}", hist.StdDev(0))
            TextBox2.Text = String.Format(hist.StdDev(0))

    End Function
    --------------------------------------------------

    Please tell me the correct description of ThisApplication.ActiveImage.HistogramSampled.


    And then Nikita taught me how to name a file and save it.
    But I don't know how to save the file with a Macro after pasting the results of the statistics.
    Please tell me how to do it.

    --------------------------------------------------
    Public Function Export_To_File() As SimpleScript
            Export_To_File = New SimpleScript

            With Measure.Data.ExportCommands.ExportToExcel(Export_To_File)
                .FileName = "C:\test.xlsx"'destination file
                .FileOptions=Export.ExportToFile.FileOptions.Append'file option
                .Visible=False'do not show Excel

                .Run("Title", "Table;Table;Table") '← I want to put the results of the statistics in this place.

            End With

    End Function
    --------------------------------------------------


    Thanks.

    Uemoto

  • Hello Uemoto,

    The code works fine in my tests:
        Public Sub PrintHistogramSampledStdDev
            'print standard deviation or the Gray image 
            Dim hist As MediaCy.IQL.Operations.IMcHistogram2 = ThisApplication.ActiveImage.HistogramSampled
            hist.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation
            Debug.Print( String.Format("Histogram standard deviation = {0}",hist.StdDev(0)))
        End Sub
    

    Please check it in a macro in the Project Workbench and then in your VB program. If something doesn't work, tell us what is the problem exactly (with description, screenshots,...).

    Yuri
  • Hello Yuri,

    Thank you for your advice.

    Certainly the codes work.
    But the value of the StdDev is not correct.

    I don't think that I used two kinds of histogram statistics,
    and I think that because something is wrong in the codes, I can't get the correct value of the StdDev.


    And then I came up with a good way to get the correct value of the StdDev.
    But in order to get it, I need a macro which copies the statistics to the clipboard.
    I made a copy to the clipboard, but it was not recorded in the macro.

    Please tell me codes which copy the statistics to the clipboard.


    Thanks.

    Uemoto

  • Hello Yuri,

    I found that when there was the ROI, the value of the StdDev was not correct.
    And I found that when there was no ROI, the value of the StdDev was correct.

    Processing does not go well if there is ROI.


    Uemoto

  • 2018-01-25-162519

    Uemoto --

    I do not know what it takes to get the HISTOGRAM STATISTICS into a STRING right off the bat but here is CODE that will put STRING S on the WINDOWS CLIPBOARD

                    'Put the current line on the clipboard
                    system.Windows.Clipboard.SetText (S)

    I hope this is helpful.

    -- Matt
  • Hello Yuri and Matt,

    Thank you for your advices.

    I tried your macro, but the four values of the StdDev in your Macro were different from the value of histogram statistics.

    However, I asked Mr. Morita of Japan Roper and got a Macro which could get the value of histogram statistics.
    And I understood two kinds of histogram statistics.

    The value on the statistics panel is not accurate.(calculated using ThisApplication.ActiveImage.HistogramSampled)
    The value calculated using ThisApplication.ActiveImage.Histogram is accurate.

    ------------------------------
    Dim hist As MediaCy.IQL.Operations.McHistogram = ThisApplication.ActiveImage.HistogramSampled
            hist.BinCount = hist.MaxBinCount 'use max bin count as in Histogram panel

            stdev = hist.StdDev(0)

            TextBox1.Text = stdev.ToString

            Dim hist2 As MediaCy.IQL.Operations.McHistogram = ThisApplication.ActiveImage.Histogram
            hist2.Interpretation = mcInterpretation.mciMonochrome 'set monochrome interpretation

            hist2.Mode = hist2.Mode And (Not MediaCy.IQL.Operations.mcHistogramMode.mchmIgnoreAoi) 'use ROI

            stdev2 = hist2.StdDev(0)

            TextBox2.Text = stdev2.ToString
    ------------------------------

    I could get both the inaccurate value on the statistics panel and the accurate value!
    I solved the issue.

    Thank you so much!

    Uemoto

Sign In or Register to comment.