Instead of quadratic ROI , I need an ellipse ROI in java(eclipse)

imagej
ellipse

#1

My object is elliptical, and so I need an ellipse ROI. for Quadratic I know that I can change the range of width and height, but I have no idea how can I choose the ellipse region in eclipse.
like the image below:

I don’t want to use GUI rather codes for the automatic finding of ellipse ROI of my object.


#2

Got to the macro recorder of ImageJ. There you can get all Java commands from GUI actions (switch to the Java recording in the combo box), see:

https://imagej.nih.gov/ij/docs/guide/146-31.html#toc-Subsection-31.1

Here a recorder result for Java:

imp.setRoi(new OvalRoi(79,48,94,49));


#3

Thanks.

I would like to have ROI which is in an ellipse shape, seems very simple
But still I don’t know what should I do, I’m new in java and imagJ.

Maybe I don’t need even use imageJ for that reason ?


#4

Start with a simple java plugin (ImageJ1 or ImageJ2 API). You will find examples here:


#5

Good day,

you wrote:

My object is elliptical, and so I need an ellipse ROI.

But you didn’t write for what purpose.

Please post the original image in TIF- or PNG-format (no screen-shot or phone-image or JPG) and tell us what you like to perform.

Are you interested in segmentation, do you need the exact ellipse-parameters?
Is the object always vertically aligned or can it appear tilted?

Please be more specific!

Regards

Herbie


#6

It’s simple. I have a 2D grid image like the pic below, I need to apply the entropy on only ROI that is defined by my object. My object is elliptical so I only need to define this static obj. The obj is always vertical. That would be nice if i could extract the whole parameters too.
I think I should be able to do it without imageJ.
Rectangular ROI is easy to define.

abc

Here is what I wrote, but Put all the value inside of the ROI with 1. I want to only choose this region and show it with a line on my image.

public EllipseGrid(int x, int y, double a, double b) {
		super(x, y, "EllipseGrid");

		// Create ellipse in the grid.
		double radiusA = a * x;
		double radiusB = b * x;
		int xcenter = x / 2;
		int ycenter = y / 2;
		float val = 1.f;

		for (int i = 0; i < x; i++) {
			for (int j = 0; j < y; j++) {
				if (Math.pow(i - xcenter, 2) / (radiusA * radiusA)
						+ Math.pow(j - ycenter, 2) / (radiusB * radiusB) <= 1) {
					super.setAtIndex(i, j, val);
				}
			}
		}
	}
}

#7

It still isn’t clear to me why Bio7’s solution won’t work for you. What is it you want to do that the built-in oval selection won’t work?


#8

So you are dealing with CT-phantoms.

If the phantom is selected, i.e. like this
selectedPhantom
what do you like to do with it?

Crop it?
Set the outside to zero?

Please be more specific!

Regards

Herbie


#9

As I said want to apply entropy and Total variation only on the object with its edge


#10

I know that you like to see Java-code but to get you started, here is an ImageJ-macro that gives you some values that may be useful for further analyses:

run("Set Measurements...", "mean standard min median kurtosis redirect=None decimal=3");
run("Find Maxima...", "noise=100 output=[Point Selection] exclude");
getSelectionBounds(x, y, width, height);
doWand(x, y, 90.0, "Legacy");
run("Measure");
exit();

Paste the above macro code to an empty macro window (Plugins >> New >> Macro) and run it.

It works for the provided sample image.

Regards

Herbie


#11

Dear Herbie, thanks but it isn’t what I’m looking for.


#12

[…] it isn’t what I’m looking for.

This is not very helpful, so please tell us what you really need.

If the problem is Java versus Macro, then please tell us whether at least the function of the macro goes in the desired direction. I’m well aware that the statistic measures are not sufficient for entropy computations. For this you need histograms.

Regards

Herbie


#13

I wrote the entropy based on the histogram and it works well.
But all I want is instead of applying the entropy ( I think as well as the histogram) for all the pixel values of my image, I rather apply them on ROI that is my object which has an ellipse shape.
i should nt do that via GUI.


#14

Sorry but the above macro doesn’t use the GUI, except for presenting the results.

The analysis is actually done within the desired (elliptic) ROI.

Please report back!

Herbie

PS:
Here is what I get with the above ImageJ-macro when run on the 8bit sample image in JPG-format:
selectedPhantom
resultsTable


#15

Thanks
As I said I’m new in java and specially imageJ.

If the yellow line show me the border , It’s like that:

Capture22


#16

Sorry but you’ve posted an 8bit JPG-image and not the original 32bit TIFF-image.
(You may post 32bit TIFF-images as Zip-archives.)

Please post the correct image!

Regards

Herbie


#17

My image is a 2D-grid (8-bit)


#18

The image posted in your previous post is “256x256 pixels; 32-bit; 256K”.

Please check!

Herbie


#19

Azi really in an honest way and I don’t want to appear rude…
please try to do some tutorial on ImageJ scripting and programming and its classes and one on java for ImageJ.

the command to draw an ellipse with java is the one pointed out by @Bio7 in the post before.

then you can get the imageprocessor (check on the API of ImageJ) with the pixels within the oval ROI and do your calculation.

at the moment I am without a computer so I am writing with a phone and I can’t easily pit the links to the resources and docs.
and I also cannot write an easy code snippet to help you more…


#20

Good day Emanuele,

I fear the original poster wants to simply select the CT-phantom and do some statistics (entropy measurements) on the selected object. No need to create ellipses though!

The present problems (from my point of view) are that the original poster didn’t post a suitable sample image. Java comes later…

Best

Herbie