Discussion:
How to display symbol for AnnotationPoint object?
Joschka
2012-07-10 12:27:15 UTC
Permalink
Hi everyone,

first of all I would like to congratulate all contributors on their
efforts, this package looks very promising to me. I plan on using the
plotting and interaction possibilities to rapidly develop image processing
utilities.
Currently I'm working on a perspective distortion tool which requires the
user to select four points in an image and then uses these points to
compute a homography for distortion correction (points are mapped to
corners of a square). As these points should be placed precisely, getting
the mouse cursor coordinates at the time of the click event is not enough.
After looking at your image_plot_tools.py example the AnnotatedPointTool
seems appropriate. However, I want to place these four points
programmatically to provide the user with an initial guess of the position
which she can change later. So I modified the example (see below) to
display four points with their corresponding labels and make them
selectable and movable. Now, the user can select these points by clicking
on an invisible point above the top left corner of the annotation frame and
move them to the correct position.
I want to display some symbol to make the selection and placement easier.
The GUI enables me to do this, by selecting one point (using the invisible
marker) and opening the Parameters window, where I can set a symbol on the
Shape or Label register. How can I achieve this in my program? I would
prefer to have a red cross as corner marker...

Thanks in advance!

Best Regards,

Joschka

Code example
----------------------

import os.path as osp

from guiqwt.plot import ImageDialog
from guiqwt.builder import make
import guiqwt.annotations as ga
from guiqwt.styles import AnnotationParam

def create_window():
win = ImageDialog(edit=False, toolbar=True,
wintitle="BIGS Corner Selection")
return win

def test():
"""Test"""
# -- Create QApplication
import guidata
_app = guidata.qapplication()
# --
filename = osp.join(osp.dirname(__file__), "brain.png")
win = create_window()
image = make.image(filename=filename, colormap="gray",
interpolation="nearest")
plot = win.get_plot()
plot.add_item(image)

corner_positions = [(-10, 0), (100, 0), (0, 100), (100, 100)]
corner_titles = ["Top Left", "Top Right", "Bottom Left", "Bottom Right"]
for point, title in zip(corner_positions, corner_titles):
parameters = AnnotationParam()
parameters.title = title
annotation = ga.AnnotatedPoint(point[0], point[1], parameters)
annotation.set_movable(True)
annotation.set_selectable(True)
plot.add_item(annotation)

win.exec_()

if __name__ == "__main__":
test()
Joschka
2012-07-13 12:28:31 UTC
Permalink
Hi,

I managed to solve my issue by importing ShapeParam and SymbolParam from
guiqwt.styles and then extending the loop in my previous example as follows:

for point, title in corner_data:
# Lines unchanged
corner_point.set_selectable(True)
symbol_param = SymbolParam()
symbol_param.alpha = 1.0
symbol_param.marker = "Cross"
symbol_param.size = 45
symbol_param.edgecolor = "red"
shape_param = ShapeParam()
shape_param.symbol = symbol_param
shape_param.sel_symbol = symbol_param

corner_point.set_item_parameters({"ShapeParam":shape_param})
Joschka
2012-07-13 12:29:41 UTC
Permalink
... where corner_point should be named annotation to match the previous
example
Pierre Raybaut
2012-07-16 18:23:48 UTC
Permalink
Hi,

I see that you solved this by yourself. Thanks for taking the time to
post the solution and please do not hesitate to ask if you need more
help.

Cheers,
Pierre
Post by Joschka
Hi,
I managed to solve my issue by importing ShapeParam and SymbolParam from
# Lines unchanged
corner_point.set_selectable(True)
symbol_param = SymbolParam()
symbol_param.alpha = 1.0
symbol_param.marker = "Cross"
symbol_param.size = 45
symbol_param.edgecolor = "red"
shape_param = ShapeParam()
shape_param.symbol = symbol_param
shape_param.sel_symbol = symbol_param
corner_point.set_item_parameters({"ShapeParam":shape_param})
Loading...