Home Image-Pro General Discussions

Resize ROI

Hi,

I have a problem with managing the ROI in Image Pro Premiere 9.1;
I have to transfer a ROI between two similar image of different size. I can copy the ROI from the first to the second image, I can rotate it, but I can't resize it in order to fit it in a larger image.

How can I do?

Best Reagards 

Luca Ferrantino

Best Answers

  • Answer ✓
    Hi Luca,

    I see what you want to do, but scaling of polygons is not supported in the UI, you can only adjust locations of handles. (scaling can be done using a macro).

    The easiest way would be to resize the image (either increase the size of original template image or decrease the size of the target image). In that case you don't have to resize ROI.

    Yuri

  • edited April 2014 Answer ✓

    Hi Luca,

    I’ve attached the project package (ScaleAllROIPolygons.ipx) for easy use. Add this project and run ScaleAllROIPolygons macro. The macro will prompt for the scaling factor and scale all ROIs polygons on the active image.

  • Answer ✓
    This macro scales ROI by multiplying XY coordinates by the scaling factor of polygon’s points. This way keeps relative position of the polygon then transferring from the small to big image.
  • Answer ✓
    Hi Luca,

    I've slightly modified Nikita's project (attached), so the ROI is scaled relative to it's center. Hopefully it's what you need.

    Yuri

Answers

  • Luca,

    What is the shape of the ROI (ellipse, rectangle, polygon)? If it's a polygon, you can adjust it dragging ROI handlers.

    Yuri
  • Here is the example
  • edited April 2014
    It is a complex polygon, so my willing is to make it bigger constraining proportion (next comment will show an example of what i want to do):

    thanks a lot

    Luca
  • Ok, I understand,
    what a pity…

     thank you very much for fast and clear answer!

    Luca
  • Luca,

    There is a possible workaround but it involves multiple steps.
    1. Load the Feature Manager and add your ROI to it.
    2. Convert the ROI to an annotation in Feature manager.
    3. Apply the new annotation to an image.
    4. Create an annotation group (add one annotation if there is only one)
    5. Then you can re-scale the group using the Shift key.
    6. Convert the annotation back to a ROI and apply to your image.
    Pierre
  • Thanks you a lot Pierre!
    It is a very smart workaround, really!
    It happens to you to that when i try to re-scale the group using the Shift key it constrains the proportion but it also automatically before modify the group into a square-size group? Not easy to explain… but it helps a lot! Thank you again!
  • edited April 2014

    The macro to scale all ROI polygons by 1.2 (“d” defines scaling factor).

     

     

     

  •  Public Function ScaleAllROIPolygons() As SimpleScript
      ScaleAllROIPolygons = New SimpleScript
      Dim image1

      With Application.DocumentCommands.ActiveImage(ScaleAllROIPolygons)
       .Run(image1)
      End With

      With Automate.ScriptingCommands.CodeCommand(ScaleAllROIPolygons)
       If .Run() Then
                    ' User Code Here
                    Dim d As Double = 1.2
                    Dim im As MediaCy.IQL.Engine.McImage
                    Dim roi As MediaCy.IQL.Features.McRegions
                    Dim ovl As MediaCy.IQL.Display.Overlays.McGraphOverlay
                    Dim x As Single, y As Single

                    im = TryCast(image1, MediaCy.IQL.Engine.McImage)
                    If im IsNot Nothing Then
                        roi = im.Aoi
                        ovl = roi.AutoDisplayOverlay
                        ovl.SetEnumFilter(MediaCy.IQL.Display.Overlays.mcGraphOverlayEnumWhat.mcgewMaster,"McGraphObjPoly")
                        For Each poly As MediaCy.IQL.Display.Overlays.McGraphObjPoly In ovl
                            For i As Integer = 1 To poly.PointCount
                                poly.GetHandle(i, x, y)
                                x = d * x
                                y = d * y
                                poly.SetHandle(i, x, y)
                            Next
                        Next
                    End If
       End If
      End With

     End Function

  • Thank you nikita, i'm quite new and macro are not my best friends…

    i tried to get it run but i can't. 
    can you see if there is something wrong?

  • Luca,

    Somehow you replaced "d" by 3.148, so instead of 

    Dim d As Double = 1.2

    you have 

    Dim 3.148 As Double = 1.2

    How could it happen? Try to paste the macro again.

    Yuri
  • I understood that the d should be replaced by my converting factor (that is 3.148)
    should I put this number instead of 1.2?

    In any case, it doesn't work, it gives me this message:

    Unexpected text.

    Module 'Macros.vb', line 1, character 12.
  • Thanks Nikita,
    it works almost well the unique problem is that together with the resizing, it goes out from the image field, so it is impossible to select it and it disappear when I select other objects. (see the screenshot).
  • Hi Yuri, Hi Nikita, thanks a lot for the explication (after knowing how it works,  having the ROI in the upper left part of the image also solve the problem) and the new one that works great as well!

    Now the problem is totally solved!

    Thanks!
Sign In or Register to comment.