MATLAB Answers

Controlling the color of crosshair raised by ginput

127 views (last 30 days)
Hello, I need to use ginput. It "raises raises crosshair in the axes" - which is fine. Unfortunately, this crosshair is black, and in the axes where I need this function the background is, usually, black too, so the crosshair is very difficult to see. Changing background is not really an option. Until now I used an old version of Matlab, where this crosshair was drawn in XOR mode, and therefore this problem did not appear. Now i am forced to upgrade to the most current version, and now the XOR is banished by Mathworks. This creates problems in the described use case, but also in other use cases. Any ideas will be greatly appreciated.
Thank you,
Naum Derzhi


Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 2 Dec 2017
You need to modify the built-in ginput() function since they forgot to add this incredibly obvious and needed option of color. For example see my attached code where I changed the [0,0,0] to [1,1,1] (white). Go to line 283
crossHair(k) = uicontrol(fig, 'Style', 'text', 'Visible', 'off', 'Units', 'pixels', 'BackgroundColor', [1 1 1], 'HandleVisibility', 'off', 'HitTest', 'off'); %#ok<AGROW>
and change the color from [1,1,1] to what you want. Those are the R, G, B values in a range of 0 to 1. Then in your code, be sure to call ginputWhite instead of ginput().
You could even make a cross hair by calling plot() instead of uicontrol() and specify a dashed line if you want.


Show 2 older comments
Image Analyst
Image Analyst on 28 Feb 2019
Yes, have a button or pulldown menu call uisetcolor()
customColor = uisetcolor
then pass customColor into your own function my_gInput(numPoints, customColor) where you pass that input to uicontrol:
crossHair(k) = uicontrol(fig, 'Style', 'text', 'Visible', 'off', 'Units', 'pixels', 'BackgroundColor', customColor, 'HandleVisibility', 'off', 'HitTest', 'off'); %#ok<AGROW>
Be sure to copy this function and change the copy, not change the original, and use my_ginput() instead of ginput(). You don't really want to change the original function - that's not a good practice.
Andreea Stanescu
Andreea Stanescu on 1 Mar 2019
It worked, but what can I do for the crosshair color to update interactively as I change the colors in the modal color picker, without the need of a click for the crosshair color to update?
Image Analyst
Image Analyst on 1 Mar 2019
You can't be in the crosshair/drawing/ginput mode simultaneously as when you're letting the user pick the color. You can't have cross hairs up while your user is clicking colors without clicking OK and then have the cross hairs change their color "live"/instantaneously as they click various color patches.
First your user picks the color with uisetcolor(), then you pass that color in to your my_ginput() as an argument.

Sign in to comment.

More Answers (0)

Sign in to answer this question.