Dividing annulus into unequal regions

Hi everyone,

I am quite new to ImageJ, and am having trouble with dividing up the donut(annulus) into multiple sectors, with different angles.

My goal is to make the image that look like this and get a histogram count of each area (A,B,C,D,E,F).
5

I already have the center of the circle coordinates to generate the ring, and I have the angles that will span each sector as well. But this is quite a hassle to manually draw with polygonal selection.

I was wondering if anyone knows a macro that will divide up the areas like the above images if all user has to put in is the center of the circle coordinates and the angles.

Thank you!

Good day,

if you like to get constructive help, then please specify the exact radii of both circles and the exact angles of the sectors.

If you prefer to do it your way, you can write an ImageJ-macro which is not very difficult.
Here is what you need:
https://imagej.nih.gov/ij/developer/macro/macros.html
https://imagej.nih.gov/ij/developer/macro/functions.html

Regards

Herbie

Hi Herbie,

Sorry about being unclear in the first post.

The exact radii of the two circles are in pixels: 49.5 pixels (smaller) and 87.5 pixels (bigger)

Angles of the sectors are as follows: A is 90 degrees total (311 to +40 degrees) B is 40 degrees (41-80) C is 40 degrees (81-120) D is 110 degrees (121-230) E is 40 degrees (231-270) F is degrees 40 degrees. (271-310).

And I was looking for a macro that divides by such and only asks the user to input center of the coordinate (two concentric circles are used to generate the annulus)

And I was looking for a macro that divides by such and only asks the user to input center of the coordinate (two concentric circles are used to generate the annulus)

As I’ve written: If nobody iis willing to write a macro for you, you have to do it yourself. The chances that someone has already written a macro that does exactly what you want are near to zero …
I’d start learning to write macros, so you need not wait for others to do your job.

Good luck

Herbie

Hi,

Will the size of the circles and sectors always be the same?
If so, you could draw the sectors with the polygon selection tool, add them to the ROI manager and save them for later use. The ‘Translate’ option in the ROI manager gives you the option to move all sectors to a different position: Calculate difference between original and new location and use this for the translation.
Regards, Peter

It will be always the same. I can’t quite identify how to draw polygonal selection tool that is good enough to pass as a sector however. Thank you for your suggestion.

If you want nicer drawn sectors you could use another approach. I use it myself to make sectors from irregular shaped inner and outer ‘circles’.
I’ll show you my global workflow. If you are interested I can give you some pieces of code to help you to make your own macro:

  • Point your mouse to the center and get the x,y coordinates
  • Use macro to draw the inner circle and put in an Array
  • Use macro to draw outer circle and put in an other Array
  • Use loop in macro to
    • draw line from the central point (x,y), with a certain angle until outside the outer circle (length > radius outer circle), check for every point in that line if it is inside or outside the inner and outer circle (use macro function Roi.contains) and put those points (crossing of line and circle) in an x and y Array.
    • do the same several times with changing angle until you reach full sector coverage: e.g. 0, 1,…40 degrees angle
  • Now you have all the points of that secor in Arrays an can draw a sector polygon based on the Arrays

This sounds really promising. Can I get some more information??

Here is some code to start with:

First a function to be used in the macro

function makeLineAngle(x, y, length, angle)
       {  // line from x,y to point at length and angle from x,y
	// angle in degrees, 12 AM = 0, 3 PM = 90 etc...360
	angleRadian = angle * PI / 180; 
	dX = round(cos(angleRadian) * length); dY = round(sin(angleRadian) * length); 
	makeLine(x,y,x+dY,y-dX); // startposition = x,y ; endposition = x+dY,y+dX 
}
macro "Test [t]" {
	//Point your mouse to the center of the circles and get the x,y coordinates
	startAngle = 10; endAngle=50;
	xSectorInnerArray = newArray(endAngle-startAngle+1); ySectorInnerArray =   newArray(endAngle-startAngle+1);
	x=500; y=500; // use your own x,y values of center	
	innerRadius = 50; outerRadius=88;
	makeOval(x-innerRadius, y-innerRadius, innerRadius*2, innerRadius*2);
	
	//  loop that make a line from center at different angles
	for (angle=10;angle<=50;angle++) {
		// make line from central point and put in Array
		a = 1; // counter for all angles in Array
		makeLineAngle(x, y, innerRadius+5, angle); // +5 to make it longer then the radius of circle
		run("Interpolate", "interval=1.0"); // interpolate to get more points
		getSelectionCoordinates(xRoiLine, yRoiLine); // put points in Array
		// first make inner circle
		makeOval(x-innerRadius, y-innerRadius, innerRadius*2, innerRadius*2);
		// loop 				
		for(i=1;i<xRoiLine.length;i++) {
			if (Roi.contains(xRoiLine[i], yRoiLine[i]) != Roi.contains(xRoiLine[i-1], yRoiLine[i-1])){
				// get the average of two points on the lineArray that are just inside and outside the innerCircle
				xInner=(xRoiLine[i]+xRoiLine[i-1])/2; 
				yInner=(yRoiLine[i]+yRoiLine[i-1])/2; 
				i=xRoiLine.length; //the point has been found so exit the loop
				xSectorInnerArray[a-1]=xInner; ySectorInnerArray[a-1]=yInner;
				print("a,xInner,yInner",a,xInner,yInner);
				a=a+1;  // next angle
				}		
			} 
		}		
	}
  • extend the macro by also collecting points from the outer circle section in an other array
  • reverse only the x and y Arrays for inner circle with this function: Array.reverse(array)
  • combine the inner and outer circle array: xSectorArray = Array.concat(xSectorOuterArray,xSectorInnerArray);
  • make ROI of sector: makeSelection(“polygon”,xSectorArray ,ySectorArray );
  • look for more ImageJ functions at https://imagej.nih.gov/ij/developer/macro/functions.html

Success!
Peter

works like a charm. May I ask how you generated the ROI files? I will have to adjust the angles for different images. Thank you for your patience!

Thanks again. also works!

Sorry Sir,

I’ve asked about the parameters before, you provided the ones I’ve used. You didn’t mention that you need a flexible solution.

This Forum is to help but not to do your work.
I’ve invested quite some time already in the supplied solution and I’m not willing to provide more unpaid work.
If you have a budget for your work, then please contact me per mesaage.

Regards

Herbie

I am on the same page as you that I was just looking for help. I just meant to better understand how you generated the ROI files so I could learn it from it and apply. But I got it figured. Thank you!

I am on the same page as you

Aha.
Please understand that I’ve generated a ROI-set according to your specifications and it means a lot of work to generalize the approach.

I just meant to better understand how you generated the ROI files so I could learn it from it and apply.

Because you are now looking for a general approach, you won’t be happy with an approach that is specialized for the given parameters — no?

But I got it figured.

Good luck

Herbie