Home Image-Pro General Discussions

ROI with defined pixel content

Hey there,
I am quite new at Image analysis, so sorry for maybe trivial questions. I would like to create a ROI with variable form but defined pixel content. How can I do that? I did not find information about this topic in the users manual. Additionally, I would like to perform the same Macro for all of the 10 ultrasound images per animal, which are in the image strip. How can I perform a Macro for a group of pictures? Locking selected windows doesnt really help. Thanks for your help!
Svenja

Best Answers

  • Answer ✓
    Svenya,

    It could be easier just to export the data from the Output window to Excel (using context menu of the Output window) and then show the graph of RelVal, which is scaled from 0 to 1:


    You can also add a line at 5% in the Excel directly (add new Series), but note that you may end up with multiple values as in this example:



    You may also modify the macro to find all values that cross 5% threshold, like this:
        Public Sub Print5PercentLevels
            If ThisApplication.ActiveImage Is Nothing Then Exit Sub
            Dim hist As McHistogram=ThisApplication.ActiveImage.Histogram
            Dim i As Integer,v As Double, prev As Double=0
            Dim sum As Double=0
            Dim vMax As Double=-1
            For i=0 To hist.BinCount-1
                v=hist.Values(i,0)
                If v>vMax Then vMax=v'find max
            Next
            'define the level
            Dim Threshold As Double=0.05'5% level
            Dim accum As Double=0
            ThisApplication.Output.Show
            ThisApplication.Output.Clear
            ThisApplication.Output.PrintMessage (String.Format("{0}" & vbTab & "{1}" & vbTab & "{2}","Bin","Int.","RelVal"))
            For i=0 To hist.BinCount-1
                v=hist.Values(i,0)/vMax'calc rel value
                If (v-Threshold)*(prev-Threshold)<=0 Then
                    'crossing value
                    ThisApplication.Output.PrintMessage (String.Format("{0}" & vbTab & "{1}" & vbTab & "{2:F4}",i,hist.BinXValues(i),v))
                End If
                prev=v
            Next
        End Sub
    

    The output for this example:

    Bin Int. RelVal
    14 14 0.0621
    25 25 0.0413
    133 133 0.0573
    187 187 0.0446


    Yuri
  • 2018-02-12-162628

    Svenja --

    I see your message and I believe I understand your request.

    I cannot try it right not but I believe this will happen if you set everything up on the CAT with the GET BUTTONS and then switch to the DOG and press CREATE SMART ROI BUTTON.

    Then you should be able to TUNE it with the + and - buttons.

    Please try this and let me know if it works.

    If it does not, I'll create a way to make it work.

    -- Matt
«1

Answers

  • Hi Svenja,

    What do you mean under ROI with "defined pixel content"? Do you mean the same shape and position? If not, can you give more details and possibly illustrations?

    Running macro on multiple images is supported by Batch functionality. You can find it on the Automate tab. You can run batch on all opened images or all images in a folder(s). The "select images" group defines the processing images set.

    Yuri

  • Hi Yuri,
    thanks for your answer. I want to perform a Grey Scale Analysis with very different ultrasound images. This is why my standardized ROI should have (for example) always the content of 2000 Pixel, but shape and position of the ROI have to stay variable. The position and shape of the ROI depends of the optimal area I choose for every image for the Grey Scale Analysis. Below two examples.
  • Hi Svenja,

    If you create ROI on every image is manually, so this step is not automated. You can use Features Manager to save some ROIs templates, then you just place them on new images and adjust position, if necessary.

    You can place ROIs on all images you want analyze (keep them opened), then open Batch Processing panel, add all images for processing, set the right macro to Loop On (your LoopOn macro should measure data and send results to Data Collector or a file) and Start the batch.  
    Here the screenshot of my example, where the macro measures intensity parameters within ROI on every image and collect the data in Data Collector:



    You can also run processing on a folder of images, in that case your macro should Prompt user to draw ROI, after ROI is created user clicks Ok in the prompt and the macro continues.

    Yuri
  • 2017-12-29-092605

    Svenja --

    It sounds like you are looking for a way to create a "smart roi" within PREMIER that would always have the same AREA but that would have a variable X and Y dimension.

    I sounds to me like you need a tool that would allow the user to define the X or the Y and then create the ROI based on that dimension with the appropriate paired dimension.

    If you set an X LINE with length of 200, the "smart roi" would create an ROI 200 WIDE and 10 TALL centered on your X LINE.

    If you set a Y LINE with length of 100, the "smart roi" would create an ROI 20 WIDE and 100 TALL centered on your Y LINE.

    Is this what you are looking for?

    -- Matt

  • Hi Matt,
    thank you, this is exactly what I want to do. But where can I find the "smart Roi" tool?
    And there is another question I would like to ask:
    I would like to use ultrasonic gray level histogram width as clinical tissue characterization. Therefore I would like to create a histogram as following:
    1) y- coordinate should be the most occuring gray- scale value set as 100% (for normalization)
    2) x- coordinate should be the distribution of all the other occuring gray-scale values in proportion to the most occuring gray-scale value.
    At the level of 5 %, 25% and 50%, I want to determine the gray level histogram width. Is it possible to create such a histogram and determine the gray level histogram width in PREMIER? Thanks for your help! Svenja

  • Hi Svenja,

    You can use McHistogram object, exposed as ThisApplication.ActiveImage.Histogram to get any histogram parameters, below is the macro (project attached) that prints relative and accumulated histogram values to the Output window. You can use it to get values from any percentile or relative to the max value:

    Imports MediaCy.IQL.Operations
    Public Module Module1
        Public Sub PrintAccumulatedHistogramValues
            If ThisApplication.ActiveImage Is Nothing Then Exit Sub
            Dim hist As McHistogram=ThisApplication.ActiveImage.Histogram
            Dim i As Integer,v As Double
            Dim sum As Double=0
            Dim vMax As Double=-1
            For i=0 To hist.BinCount-1
                'calculate sum
                v=hist.Values(i,0)
                sum+=v
                If v>vMax Then vMax=v'find max
            Next
            Dim accum As Double=0
            ThisApplication.Output.Show
            ThisApplication.Output.Clear
            ThisApplication.Output.PrintMessage (String.Format("{0}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "{3}" & vbTab & "{4}","Bin","Int.","Val","RelVal","Acc%"))
            For i=0 To hist.BinCount-1
                'Print Histogram index, Intensity value of the Bin, Value, Accumulated percentage
                v=hist.Values(i,0)
                accum+=v'calculate accumulated histogram
                ThisApplication.Output.PrintMessage (String.Format("{0}" & vbTab & "{1}" & vbTab & "{2}" & vbTab & "{3:F4}" & vbTab & "{4:F2}",i,hist.BinXValues(i),v,v/vMax,100*accum/sum))
            Next
        End Sub
    End Module
    

    The output looks like this 


    Yuri
  • Thanks a lot Yuri! Your macro runs now.
    Now I would like to change the histogram y-coordinate so that the relative values are displayed (scale 0 to 1; 1 =most occuring gray scale value ).
    Is it possible to show at the data collector the min and max bin (or gray level value) on the x-coordinate at the level of 5 % (= 0,05) on the y- coordinate? That is what I need to see the histogram width at the 5% level (see NGHB on my image above).
  • 2018-01-02-092137

    Svenja --

    The SMART ROI TOOL that I described is not a FEATURE of PREMIER but it is possible through CODE running within the PROJECT WORKBENCH.

    I believe it would take me about an hour to DEVELOP and TEST the CODE for a SMART ROI TOOL.

    I have several tasks on my TO DO LIST that must be accomplished before I can allocate time to this task.

    If all goes well, I should be able to allocate time for this later today (TUE).

    If you solve this yourself, please let us know here.

    -- Matt

  • Matt,
    if it is possible for you, I would be very happy if you would try to program the smart ROI tool. I am missing the IT-brain for that :-(
  • 2018-01-02-171209

    Svenja --

    I took some time this afternoon and created a SMART ROI PROJECT that includes a SMART ROI APP.

    The DIALOG BOX for this APP is shown below.


    The IPX FILE which contains this PROJECT / APP is posted here as

        Smart Roi Project V1A.ipx

    The header for the IPP FILE and VB FILE (shown below) give a little information about the PROJECT / APP.

    Use

        APPS RIBBON + SEARCH SECTION + OPEN PROJECT

    to add the APP to the APPS SECTION.

    If this APP is started on an uncalibrated IMAGE with dimensions 1000 * 1000, it should appear as shown in the 1st image below.  The defaults for the ROI are a fraction of the IMAGE WIDTH and a fraction of the IMAGE HEIGHT in the CENTER of the image

    If the image is calibrated, the APP will appear something like shown in the 2nd image below.

    If you press the CREATE SMART ROI BUTTON, the APP will create the ROI on the ACTIVE IMAGE.

    If your image contains an ROI, press the GET FROM CURRENT ROI in the AREA and the CENTER sections of the DIALOG BOX to read these values from the ROI.  The WIDTH and HEIGHT will be set to the SQUARE ROOT of the AREA.

    Now you can open another image calibrated in the same way and create an ROI with approximately the same area.

    You can change the WIDTH and HEIGHT of the ROI with the "-%" and "+%" buttons and the APP will maintain approximately the same AREA.  Since the ROI is composed of pixels, the AREA will change a bit.  This is shown in the last 2 images below.

    Work with this a bit and see if it gives you the tool you need.

    I hope this is helpful.

    -- Matt

    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

    '------------------------------------------------------------------------------
    '
    'SMART ROI V1A
    '
    'BY:
    '
    'Matthew M. Batchelor
    'President and Applications Engineer
    'Alces Imaging and Automation, LLC
    '2906 Blue Wind Court
    'Houston, TX
    '77084
    '
    '------------------------------------------------------------------------------
    '
    'This program allows its users to create an ROI within an IMAGE and then
    'duplicate that ROI in another image or modify the ROI to contain the same
    'amount of area.
    '
    'Due to roundoff caused by the integer nature of PIXELS, the AREA of the ROI
    'will change slightly.
    '
    '------------------------------------------------------------------------------
    '
    'MODIFICATION LOG:
    '-- V1A
    '2018-01-02
    '
    '------------------------------------------------------------------------------









  • Hi Matt,
    I have pasted Smart Roi Project V1A.ipx into Apps-->Search-->Open project, but  I cannot find the App. I have chosen Image pro premier as destination.
    In the App Center at Premier it is also not linked. Could you give me a hint, where I can find your App?
  • 2018-01-03-090917

    Svenja --

    The CODE in the

        Smart Roi Project V1A.ipx

    IPX FILE needs to be loaded into the PREMIER PROJECT WORKBENCH before you will see the

        SMART ROI APP V1A BUTTON

    in the APPS SECTION of the APPS RIBBON.

    Instructions for INSTALLING APPS via IPX FILES can be found in the IMAGE-PRO PREMIER ONLINE HELP as shown below.

    I hope this information is helpful.

    -- Matt

    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-



  • Matt,

    It looks like you haven't attached the IPX file to the post.

    Yuri

  • 2018-01-03-132546

    Sorry.

    I thought I did.

    Here it is.

    -- Matt

  • Thank you. I installed the app as described and it is now at my project workbench.
    Now appeared a new problem:
    Restarting Premier, the software opens directly the project workbench and an error message (screenshot 1). Closing the workbench and trying to apply the smart roi app at an image, it doesnt work. It is noticeable that there is no unit shown (screenshot 2) in the app (neither pixel nor cm, as calibrated). Do you have an idea?
  • Hi Svenya,

    Matt may give you more details, but it looks like you don't have active image, so units issue is related to that (units are taken from the active image). 
    Regarding the macro error: it looks like the app doesn't handle the situation when no image is opened (Matt may look at that), so, avoid showing the app dialog with no images. Also be sure you are using the latest version of Premier with all updates, it should be 9.3.3.

    Otherwise the app works well, nice app Matt!

    Yuri

  • 2018-01-04-093012

    Yuri --

    Thank you for the compliment.

    Svenja --

    I did the DEVELOPMENT and TESTING on this PROJECT / APP in PREMIER 3D 9.3.2.

    There is CODE within the APP to handle the case of NO IMAGE, NO CALIBRATION, and NO ROI.

    When I start PREMIER 3D 9.3.2 with the APP LOADED and RUNNING, my PREMIER looks like shown in the 1st image below.

    When I open a CALIBRATED IMAGE, and the APP is LOADED and RUNNING, my PREMIER looks like shown in the 2nd image below.

    When I open an UNCALIBRATED IMAGE, and the APP is LOADED and RUNNING, my PREMIER looks like shown in the 3rd image below.

    The error that you have documented as


    and the appearance of the UI (USER INTERFACE / DIALOG BOX) indicates that the APP is not LOADING and RUNNING correctly on your computer.

    This is the DESIGNER VIEW of the UI that I see in my PROJECT WORKBENCH


    Perhaps one of the PREMIER GURUS can look at the error that is being displayed on your system.

    After a bit of thought, I tried something and I think it may be a clue . . .

    When I set up my PREMIER to display the WELCOME SCREEN and then I started PREMIER with the APP up and running, the following was shown.


    In my PREMIER, I use the FILE + OPTIONS + WELCOME SCREEN = UNCHECKED as shown below.


    Please try set up your PREMIER in this way, restart PREMIER, and let us know if the PROJECT / APP operates properly.

    !!NOTE !!
    The WELCOME SCREEN can also be suppressed by unchecking the SHOW PAGE AT STARTUP at the bottom of the WELCOME SCREEN. **

    I hope this information is helpful.

    -- Matt

    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-




  • Matt and Svenya,

    The app uses "If (ThisApplication.Documents.Count > 0) _" check before it gets to image properties. It will fail if Premier has Welcome page or other non-image windows active.
    I would recommend to replace it by "If (ThisApplication.ActiveImage IsNot Nothing) _" and everything will work properly without errors. Svenya, you can do it yourself (just do search and replace).

    Yuri

  • 2018-01-04-104236

    Yuri --

    Thank you for this diagnosis and resolution.

    I'll make use of this in future applications.

    -- Matt
  • Hi Yuri and Matt,
    first thanks for all your work and thinking on my problems!
    I have updated my Premier from version 9.2 step by step to version 9.3.3 (as you recommended, Yuri). Now all my macros and apps disappeared and it isnt even possible to see or open "automate" and "app" in the ribbon tab. I have sent an error documentation and will wait to news by the technical support.
  • Hi Svenja,

    I don't know what the problem you have exactly, but note, that Premier 9.3 is installed into different folder (parallel to 9.2), so you may need to re-add your projects to 9.3.

    Yuri
  • Hello Yuri and Matt,
    program is running again now with version 9.3.0 and Makros and ribbon tab are complete again. I am now working  with the smart ROI app by Matt. The units are shown in pixel or cm. We replaced your ThisApplication.Documents.Count > 0 with ThisApplication.ActiveImage IsNot Nothing  as recommended. The first question is, if it should be replaced this way at the whole script or just at a special position of it? I am unfortunately not keen at programing..
    Second question is as following: I have opened an active image, that is cailbrated. When I enter width and heigth of the smart roi and push on "create smart ROI", following error appears. Do you have an idea?
    Kind regards Svenja
  • Hi Svenya,

    You can replace  ThisApplication.Documents.Count > 0 with ThisApplication.ActiveImage IsNot Nothing everywhere in the project.

    Regarding the error: it might be related to decimal separator on your system, which is comma, the Val function than converts text to numbers (that's used in the app) may not handle comma as decimal separator and return 0, which will cause your error.

    As a workaround, you may change regional settings of your Windows to use "." as decimal separator (or use just integer numbers for ROI size).

    Otherwise you will have to replace Val() function in the SmartRoi_MakeRoi sub by an equivalent function that handles comma as decimal separator properly, such as Double.Parse().

    Yuri

  • Hi Yuri,
    it seems to me that the app has difficulties to identify the open image as active image. I tried your advice using "." instead of "," and it worked the first time. The image appeared above the app window. Trying to use the app again for a second image, it refuses to work again. Neither analysing an existing ROI nor creating a new smart ROI works. I restarted Premier, closing app and image, but also after restart the app doesnt work. Maybe something is still working in the background? It is interesting, that the image doesnt appear anymore above the app window.
    Svenja
  • Hi Svenja,

    I don't know what the problem you have with layers, but I always use SDI mode, in that case you don't have any issues with overlapping windows. SDI mode is the default and can be activated from the ribbon bar as on my screenshot below:



    Yuri
  • Hey Yuri,
    1) on your script for the histogram width, did you use the max grey-value or the most grey- value for normalisation? For me it seems you took the max grey-value. For my project, I would prefer the most grey- value. Is there an option to change that?
    2) I want to generate three further parameters from my data. They are contrast, homogeneity and mean gradient. I have formulae for these parameters, but do not know how to teach PREMIER these formulae and how to generate my parameters.. Do you have an idea for that?
    3)With the smart ROI app I am still in progress and will give answer, when I tried out everything. SDI mode is running by default and I think, it is not the problem.
    Thanks a lot!
    Svenja
  • Hi Svenja,

    1) I used histogram max bin value (Mode), you can see it in the code. What is "most grey-value"?
    2) IP Premier can generate Heterogeneity measurement (check Count/Size measurements). Complexity of calculations of other parameters depends on the formula and whether it can be calculated from histogram or needs raw pixel data. Check GetArea/PutArea examples that show how you can get access to every pixel (http://forums.mediacy.com/discussion/comment/2687#Comment_2687 )

    Yuri
  • Hi Yuri,
    1) the most represented grey- value in the histogram ist the "most grey-value". For example, when there are 2000 pixels in a ROI and 1800 have the grey-value 78, then 78 is the "most grey-value". I would like to use the most represented grey value in the histogram of every image for normalisation (in my example should 78 set as 100%).
    2) I have added below the formulae for contrast and mean gradient value. It should be calculable from histogram. Do you have an idea?
    kind regards Svenja
  • Hi Svenja,

    1) That's how I calculated my value, as you can see from the code. 
    2) It looks like the values are calculated from pixel values, not histogram, so you should check my suggestion of using GetArea/PutArea.

    Yuri

Sign In or Register to comment.