Hi,
I would like to generate a cross hair as overlay. It should gain exactly that visual property known from the cross hair cursor: Those line parts which cover bright background should appear dark and vice versa. What would be the best approach to it? Regards Christian Kreutzfeldt -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
>Those line parts which cover bright background should appear dark and
vice versa. This happens when you draw the line in XOR mode. Another nice thing about XOR mode is if you draw it twice the line disappears. Even better, for a cross hair when you draw two crossed lines the center point does get drawn twice and so will show up as the original value. As far as I know IJ doesn't support XOR drawing mode directly. Here's how to do it in a macro, but you could use the same approach in Java: http://osdir.com/ml/java.imagej/2005-05/msg00064.html The important thing is to get the pixel value, XOR with cursor value (0xff in 8-bit mode) and then put the pixel. An alternate approach would be to draw a cross hair with light and dark lines that will show up against either a light or dark background. See the attached image and the following code snippet. Aivar private static final Color CURSOR_COLOR = Color.WHITE; private static final Color CURSOR_SHADOW = Color.GRAY; private static final int CURSOR_WIDTH = 11; private static final int CURSOR_HEIGHT = 11; . . . // to create the cursor overlay Overlay overlay = new Overlay(); cursorRoi = new ImageRoi(0, 0, createCursorImage()); imagePlus.setOverlay(overlay); . . . private BufferedImage createCursorImage() { int color = getColor(CURSOR_COLOR, 0xff); int black = getColor(CURSOR_SHADOW, 0xff); BufferedImage cursorImage = new BufferedImage(CURSOR_WIDTH, CURSOR_HEIGHT, BufferedImage.TYPE_INT_ARGB); for (int y = 0; y < CURSOR_HEIGHT; ++y) { for (int x = 0; x < CURSOR_WIDTH; ++x) { if (x == CURSOR_WIDTH / 2 - 1 || x == CURSOR_WIDTH / 2 + 1) { if (y <= CURSOR_HEIGHT / 2 - 1 || y >= CURSOR_HEIGHT / 2 + 1) { cursorImage.setRGB(x, y, black); } else if (y == CURSOR_HEIGHT / 2) { cursorImage.setRGB(x, y, color); } } else if (x == CURSOR_WIDTH / 2) { if (y != CURSOR_HEIGHT / 2) { cursorImage.setRGB(x, y, color); } } else if (y == CURSOR_HEIGHT / 2 - 1) { cursorImage.setRGB(x, y, black); } else if (y == CURSOR_HEIGHT / 2) { cursorImage.setRGB(x, y, color); } else if (y == CURSOR_HEIGHT / 2 + 1) { cursorImage.setRGB(x, y, black); } } } return cursorImage; } private int getColor(Color color, int alpha) { int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); return (alpha << 24) | (red << 16) | (green << 8) | blue; } . . . // to move it around public void showCursor(int x, int y) { x -= CURSOR_WIDTH / 2; y -= CURSOR_HEIGHT / 2; cursorRoi.setLocation(x, y); imagePlus.draw(); } On 12/14/12 3:53 AM, Phase GmbH wrote: > Hi, > > I would like to generate a cross hair as overlay. It should gain > exactly that visual property known from the cross hair cursor: Those > line parts which cover bright background should appear dark and vice > versa. > > What would be the best approach to it? > > Regards > > Christian Kreutzfeldt > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
If you do use my code, it's missing an "overlay.add(cursorRoi)" to hook
things together. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Phase GmbH
On Dec 14, 2012, at 4:53 AM, Phase GmbH wrote:
> Hi, > > I would like to generate a cross hair as overlay. It should gain exactly > that visual property known from the cross hair cursor: Those line parts > which cover bright background should appear dark and vice versa. > > What would be the best approach to it? ImageJ supports custom crosshair cursors. Simply add a GIF image named "crosshair-cursor.gif" to the ImageJ/images folder and restart ImageJ. To customize it, open it in ImageJ, convert to RGB, edit, convert back to 8-bit indexed color, set "GIF and PNG transparent index" in Edit>Options>Input/Output to the index of the background color and save as GIF. I attached an example, which is also available at <http://imagej.nih.gov/ij/images/crosshair-cursor.gif>. -wayne [cid:[hidden email]] [cid:[hidden email]] -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |