MakeOval Making Circles in Top Left Corner of Image:

Hi everyone,

I’m trying to analyze some samples (example image here: https://www.physicsforums.com/insights/wp-content/uploads/2015/09/tem.png), and everything seems to be working well except for the step where I am supposed to create four ovals in the area around the center of mass of the particles I am analyzing. Here is a part of the code:

selectWindow("_**FILENAMEHERE.EXT**_"); //Will have to open picture and change line to match file name
run("Set Scale...", "distance=468 known=2 pixel=1 unit=nm");
run("8-bit");
run("Duplicate...", " ");
run("Threshold...");
setAutoThreshold("Mean dark");
setOption("BlackBackground", false);
run("Convert to Mask");
//run("Despeckle");
//run("Make Binary");
//run("Erode");
//run("Erode");
//run("Minimum...", "radius=2");
run("Set Measurements...", "mean center limit add redirect=[_**FILENAMEHERE.EXT**_] decimal=3"); //Rename redirect here
run("Analyze Particles...", "size=1.5 circularity=0.2 pixel show=Nothing display clear add");
rad = getNumber("Input circle radius", 0);
numberOfPoints = getValue("results.count");
waitForUser("Start Data Analysis after this point:")
waitForUser(numberOfPoints)
//Creation of circles in particles
for (i = 0; i < numberOfPoints; i++) {
    X = getResult("XM", i);
    //waitForUser(X); **Be careful with this command. Only disable when the for loop is broken or ends quickly.**
    Y = getResult("YM", i);
    //waitForUser(Y); **Be careful with this command. Only disable when the for loop is broken or ends quickly.**
    //setTool("oval");
    //waitForUser(rad); **Be careful with this command. Only disable when the for loop is broken or ends quickly.**
    //waitForUser(X-(rad/2)); **Be careful with this command. Only disable when the for loop is broken or ends quickly.**
    //waitForUser(Y-(rad/2)); **Be careful with this command. Only disable when the for loop is broken or ends quickly.**
    makeOval(X-(rad/2), Y-(rad/2), rad, rad);
    roiManager("Add");
    makeOval((X-(rad/2))+1, Y-(rad/2), rad, rad);
    roiManager("Add");
    makeOval((X-(rad/2))+1, (Y-(rad/2))+1, rad, rad);
    roiManager("Add");
    makeOval((X-(rad/2)), (Y-(rad/2))+1, rad, rad);
    roiManager("Add");
//}

The problem I’m having is that the ovals appear in the top left corner of the image, even when I am certain that the program understands where the ovals should be. The program returns to me values that make sense for random particles but still puts the ovals in the top left corner. Any help here would be great.

Additionally, you should be able to run the code with that image and get to the step that I’m seeing, which is just a huge yellow region at the top left corner which if zoomed in you can see all the individual circles that were supposed to be over the particles. The strange thing is that this particular code works on simple images like a black and white polka dots image (I would recommend trying it with a white background and black dots), and the ovals are in the general area of where they are supposed to be. They are not perfect as the coordinates denote where the upper left corner of the bounding rectangle is, but it is certainly a start.

Thanks everyone.

Hi Lorundir,

Is this macro written for this image? If so the scale is way off, try correcting it and see what happens.

run("Set Scale...", "distance=22.33 known=2 pixel=1 unit=nm");

image

But in any case I’d say the resolution of this image is too low to get a nice result using this method.

Sverre, thanks for the reply.

No the macro is written for a different type of image, which is why the result looks so bad. However, the problem still is the same: the circles that are supposed to be over the individual particles are drawn in the top left corner. You can verify that the circles actually are being told to be drawn over the particles by uncommenting the waitForUser commands inside the for loop, breaking the for loop, and putting some number in the getResult commands between, say, 1 and 1500.

The program will indeed return the center of mass for a particle and also give the location of the top left corner of the circle, which both make sense. Perhaps I don’t really understand how the MakeOval command works. I’ve tried removing X and Y from the location specification, and putting in actual numbers (like 50) in the location specification.

Putting in actual numbers seems to actually change the position of the circles, but removing X and Y (so you just have rad/2 in the specification) doesn’t seem to have much of an effect. I suspect that the command is not reading the variable X and Y and going straight to the rad/2 value.

L

I can have a look at it tommorow, or maybe someone will see the mistake before then. Can you share one of the actual images that you use?

It is easier for people to troubleshoot your macro if they can run it directly and get the same issue you are getting.

When I changed the scale, I see ovals all over the place, no?

Sverre,

I’m afraid not–the project is confidential and I don’t know how much information I’m actually allowed to post.

Sorry about the late reply–I’ve an exam today and I’m preoccupied with that, but I will get back to you soon with something.

Thank you again for your patience and help.

L

1 Like

Sverre,

Found the issue out from another forum: MakeOval reads the location in pixels, not the scale of the image. So It turned out that I was supposed to use getPixelSize to find the resolution of the image and use that as a conversion factor for my MakeOval commands.

As an example, we first run getPixelSize and pull values from the ROI manager as the macro does…

getPixelSize(unit, pixelWidth, pixelHeight)

…and ask FIJI to draw an oval at the specified coordinates. However this line below,

makeOval(X-(rad/2), Y-(rad/2), rad, rad);

…becomes

makeOval((X/pixelWidth)-(rad/2), (Y/pixelHeight)-(rad/2), rad, rad);

L

1 Like