Analyze Colors from an area in an image and set a high readable Fontcolor

Hey, i want to invert the colors from an area in an image. I am coding in Java and i have to create a new plugin without macros. How can i select a special Roi? When i want for example to analyze the under half of an image.
Then i have to analyze the colors. After that i have a subtitle i have to colorize. The color must be perfectly readable. Any Ideas?

It appears as if you are not sufficiently familiar with ImageJ. Consequently, ii is highly recommended that you first try to achieve what you want by using the GUI and the Macro-recoder. If you are happy with the workflow, you may start coding a Java-plugin.

Make a suitable selection (RoI) and invert its pixels.
Both can be done using the ImageJ-GUI.
You may use the Macro-recoder to record the actions.
(You may even record the Java-code.)

2 Likes

Thanks for your answer. you are right, i am not really familiar with ImageJ. I have to do a plugin for my university and i dont know how to do it :confused: its not accepted to do it with macros… :frowning:

Despite Corona, you need to perform your student projects yourself – no?

Start as described above and only later write Java-code.

1 Like

Well okay, i try it with the macro recorder. But i dont know how to do it with the macro recorder too. I will try more. May you can give me a tip where i can finde the macros i am searching for

What about studying the ImageJ-User Guide? (Subsection 31.1.4 may help.)

Here is the macro I get for a loaded sample image:

run("Clown");
makeRectangle(37, 62, 48, 64);
run("Invert");

Paste the code lines to an empty macro window (Plugins >> New >> Macro) and run it. (You need an open internet connection to load the demo image.)

Here is the resulting image:
clown_proc

Here is the Java-code generated by the Recorder:

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class My_Plugin implements PlugIn {

	public void run(String arg) {
		ImagePlus imp = IJ.openImage("https://imagej.net/images/clown.jpg");
		imp.setRoi(37,62,48,64);
		IJ.run(imp, "Invert", "");
		imp.show();
	}

}
1 Like