Get ROI center and zoom to center of display
What is the simplest way to center a measurement ROI on screen?
My ROIs are irregular on different places in large images and include segmented objects.
Basically I might also use the coordinates of an object, but guess it would be easier to get the ROI mass center (or middle of width and height?). It does not need to be very precise...
I want to get a PPT export of the view for each measurement hence simply call a function do so.
e.g.
Public Function testsdsd() As SimpleScript
testsdsd = New SimpleScript
Dim window1, doc1
With Application.WindowCommands.Active(testsdsd)
.Run(window1)
End With
With Application.WindowCommands.Restore(testsdsd)
.Run(window1)
End With
With Application.WindowCommands.Maximize(testsdsd)
.Run(window1)
End With
With Application.DocumentCommands.Active(testsdsd)
.Run(doc1)
End With
With Measure.MeasurementsCommands.Options(testsdsd)
.Classes = New System.Collections.Generic.List(Of MMClassDescr)
.Classes.Add(New MMClassDescr("Total IR",System.Drawing.Color.FromArgb(CType(146, Byte),CType(208, Byte),CType(80, Byte)),ePointShape.LargeTarget90))
.Run(doc1)
End With
'HOW TO GET COORDINATES OF CENTER ROI AND ALIGN ROI CENTER WITH DISPLAY CENTER
With View.ImageViewCommands.Options(testsdsd)
.View.Magnification = 0.0987651321423681R
.View.Scroll = 1460
.View.Pan = 879
.Run(window1)
End With
With View.ImageViewCommands.Options(testsdsd)
.View.AutoZoomMode = MediaCy.IQL.Display.Viewer.mcAutoZoomMode.mazmNone
.Run(window1)
End With
With Application.WindowCommands.ExportToPowerPoint(testsdsd)
.Export = Window.ExportToPowerPoint.ExportOptions.DocumentView
.Run(New List({window1}))
End With
End Function
Thanks
Dan
Best Answer
-
Hi Dan,
If you select measurement objects in the Data Table, the view is automatically centers on the selected object with the current zoom.
If you want to zoom on the object as well, the macro below shows how to do that. It zooms to the first selected measurement object (or the first object, if nothing is selected):Imports MediaCy.Addins.Measurements Imports MediaCy.IQL.Display.Viewer Public Module Module1 Public Sub ZoomToObject Dim im As McImage=ThisApplication.ActiveImage If im Is Nothing Then Exit Sub Dim md As McMMData=im.MeasurementsData If md.Count=0 Then Exit Sub Dim sf As McMMSubFeature=Nothing If md.SelectedSubFeatures.Count>0 Then sf=md.SelectedSubFeatures(0)'get first selected sub-feature Else sf=md.SubFeatures(0)'get first sub-feature End If ZoomToSubfeature(sf) End Sub Public Function ZoomToSubfeature(sf As McMMSubFeature) Dim view As Mediacy.IQL.Display.Viewer.McView=ThisApplication.ActiveWindowEx.ImageView With view Dim ZoomX As Double, ZoomY As Double, W As Long, H As Long Dim l As Single, r As Single, t As Single, b As Single sf.GetBoundingBox(l, t, r, b) Dim rect As New System.Drawing.RectangleF(l,t,r-l+1,b-t+1) Dim centerX As Single=l+(r-l)/2 Dim centerY As Single=t+(b-t)/2 Dim dx As Single = 2 rect.Inflate(dx,dx)'add border 'calculate zoom to fit object in X and Y directions ZoomX = .ClientWindowWidth / rect.Width ZoomY = .ClientWindowHeight / rect.Height 'set lowest magnification .Magnification = System.Math.Min(ZoomX, ZoomY) Dim NewPan As Integer = System.Math.Max(0, (centerX - (.ClientWindowWidth / .Magnification) / 2)) Dim NewScroll As Integer = System.Math.Max(0, (centerY - (.ClientWindowHeight / .Magnification) / 2)) If ZoomX>ZoomY Then .SetPanScroll(NewPan, rect.Top) Else .SetPanScroll(rect.Left, NewScroll) End If End With End Function End Module
I've also attached the project.
Regards,
Yuri0
Answers
With these modifications it works for the ROI
Imports MediaCy.Addins.Measurements
Imports MediaCy.IQL.Display.Viewer
sf=md.SelectedSubFeatures(0)'get first selected sub-feature
Else
sf=md.SubFeatures(0)'get first sub-feature
ZoomToSubfeature(sf)