MATLAB Answers

Controlling the color of crosshair raised by ginput

113 views (last 30 days)
Naum Derzhi
Naum Derzhi on 1 Dec 2017
Commented: Image Analyst on 27 Feb 2021 at 3:51
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 7 older comments
Image Analyst
Image Analyst on 15 Jan 2021
You're probably trying to modify the original ginput.m in the c\program files\matlab folder. Don't do that. Make a copy of it in your MATLAB utilities folder (where you might store all your custom-written utility m-files), or your folder with all your m-files in it. Then make the change to that file.
Daffa Faisal
Daffa Faisal on 27 Feb 2021 at 0:38
sorry but I still dont get where to place the new my_ginput file to the library
Image Analyst
Image Analyst on 27 Feb 2021 at 3:51
Place it in the folder where your own, custom main m-file is, or in any other folder where you keep custom m-files (utilities) that is on your search path. Just be sure not to call it ginput.m. If you still don't understand, then tell me what folder is the m-file that you want to call ginputWhite in? Ok, put ginputWhite.m in THAT folder.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!