Hi all,
Beside my previous post i need some help on the same matter. I encounter some problem during the automatic analysis by the plugin made. I know what the problem is and I wanted to check by a macro made which was the base for the plug in made by a person active in the forum at that time (see previous post). The task on this images (see example) is to create a profile from an image and store the xy values in a text file. This text file is then processed in a commercial metrology software. The first action is converting the image in 8bit; autotresholding; and then create the profile from skeletonizing the detected particle. When there is some artefact in the background the automeasure(plugin) only calculate the pictures without artefacts. I know the artefacts are the reason because if you erase them or paint them by the background color the images still can be processed. It takes extra time and as a matter of fact it is no longer auto measuring. I think it can be solved by change the detection parameters from 0 to infinity to a certain area limit, by this the smaller artefacts can be excluded from the measurements; However there seems something wrong with the macro which is made mainly in java code, not the marcro language. When I try to run the macro, nothing happens. Normally before 2 buttons were created into the imageJ menu bar, one for the calibration the other for the processing. If I can make this macro running again, I can check if this works and if it works see how to implement in the plugin with help from some experts. Below is the code of the macro that is not running Thanks in advance, Martin. var xMax, xMin, yMax, yMin; var path, dir, resultsDir, name, list, name1; var micronsPerPixel = 0.111; var xpts, ypts; var checkData, savePlot, checkResults; macro "Manual Calibrate Tool - CfffD4aD4bD4cD4dD4eD58D59D5aD5eD60D61D62D63D64D65D66D67D68D70D71D76D80D81D82D83D84D85D86D87D88D94D95D98D99D9aD9fDaaDabDacDadDaeCf00D00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD1fD20D21D22D23D24D25D26D27D28D29D2aD2bD2cD2dD2eD2fD30D31D32D33D34D35D36D37D38D39D3aD3bD3cD3dD3eD3fD40D41D42D43D44D45D46D47D48D49D4fD50D51D52D53D54D55D56D57D5bD5cD5dD5fD69D6aD6bD6cD6dD6eD6fD77D78D79D7aD7bD7cD7dD7eD7fD89D8aD8bD8cD8dD8eD8fD90D91D92D93D96D97D9bD9cD9dD9eDa0Da1Da2Da3Da4Da5Da6Da7Da8Da9DafDb0Db1Db2Db3Db4Db5Db6Db7Db8Db9DbaDbbDbcDbdDbeDbfDc0Dc1Dc2Dc3Dc4Dc5Dc6Dc7Dc8Dc9DcaDcbDccDcdDceDcfDd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9DdaDdbDdcDddDdeDdfDe0De1De2De3De4De5De6De7De8De9DeaDebDecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDff"{} macro "Manual Calibrate Tool Options" { Dialog.create("Set Calibration"); Dialog.addNumber("microns per pixel:", micronsPerPixel); Dialog.addCheckbox("Show Results", false); Dialog.addCheckbox("Save Plots", false); Dialog.addCheckbox("Check each result", false); Dialog.show(); micronsPerPixel = Dialog.getNumber(); checkData = Dialog.getCheckbox(); savePlot = Dialog.getCheckbox(); checkResults = Dialog.getCheckbox(); } macro "Run Tool - Cf00D00D01D02D03D04D05D06D07D08D09D0bD0cD0dD0eD0fD10D11D12D13D14D15D16D17D18D1aD1bD1cD1dD1eD1fD20D21D22D23D24D25D26D27D29D2aD2bD2cD2dD2eD2fD30D31D32D33D34D35D36D37D39D3aD3bD3cD3dD3eD3fD40D41D42D43D44D45D46D47D48D4aD4bD4cD4dD4eD4fD50D51D52D53D54D55D56D57D58D59D5bD5cD5dD5eD5fD60D61D62D63D64D65D66D67D68D6aD6bD6cD6dD6eD6fD70D71D72D73D74D75D76D77D79D7aD7bD7cD7dD7eD7fD80D81D82D83D84D85D86D88D89D8aD8bD8cD8dD8eD8fD90D91D92D93D94D95D97D98D99D9aD9bD9cD9dD9eD9fDa0Da1Da2Da3Da4Da6Da7Da8Da9DaaDabDacDadDaeDafDb0Db1Db2Db3Db4Db6Db7Db8Db9DbaDbbDbcDbdDbeDbfDc0Dc1Dc2Dc3Dc4Dc5Dc7Dc8Dc9DcaDcbDccDcdDceDcfDd0Dd1Dd2Dd3Dd4Dd5Dd6Dd9DdaDdbDdcDddDdeDdfDe0De1De2De3De4De5De6De7De9DeaDebDecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df8Df9DfaDfbDfcDfdDfeDff"{} macro "Run Tool Options" { setup(); for (i=0; i<list.length; i++){ setBatchMode(true); if (!endsWith(list[i], "/")) { open (list[i]); processImage(); closeImage(); } setBatchMode(false); } } function setup() { path = File.openDialog("Select a File"); dir = File.getParent(path); name = File.getName(path); list = getFileList(dir); dot = lastIndexOf(name, "."); name1 = substring(name, 0, dot); resultsName = name1 + "_results"; resultsDir = dir+resultsName+File.separator; File.makeDirectory(resultsDir); } function processImage() { dot = lastIndexOf(getTitle(), "."); name1 = substring(getTitle(), 0, dot); run("8-bit"); setAutoThreshold("Default dark"); setOption("BlackBackground", false); run("Convert to Mask"); pos = positionOfLargestParticle(); x = getResult("XStart", pos); y = getResult("YStart", pos); doWand(x, y); setForegroundColor(0, 0, 0); run("Enlarge...", "enlarge=1 pixel"); run("Fill", "slice"); run("Enlarge...", "enlarge=-1 pixel"); setForegroundColor(255, 255, 255); run("Fill", "slice"); run("Select None"); setOption("BlackBackground", false); run("Skeletonize"); pos = positionOfLargestParticle(); x = getResult("XStart", pos); y = getResult("YStart", pos); doWand(x, y); print("X; Y"); print("µm; µm"); xMax = 0; xMin = 1000000; yMax = 0; yMin = 1000000; start = false; end = 0; counter = 0; Roi.getCoordinates(xpoints, ypoints); xpts = newArray(xpoints.length); ypts = newArray(ypoints.length); xp = newArray(xpoints.length); yp = newArray(ypoints.length); for(i = 0; i < xpoints.length; i++) { x = xpoints[i]; y = ypoints[i]; xpts[i] = x; ypts[i] = y; if(yMax < ypts[i]) yMax = ypts[i]; if(yMin > ypts[i]) yMin = ypts[i]; if(xMax < xpts[i]) xMax = xpts[i]; if(xMin > xpts[i]) xMin = xpts[i]; } for(i = 0; i < xpoints.length; i++) { x = xpoints[i]; y = ypoints[i]; if(x == xMin) { start = true; end = i; } if(start) { xp[counter] = x; yp[counter] = y; counter++; } } counter--; for(i = 0; i < end; i++) { x = xpoints[i]; y = ypoints[i]; xp[counter] = x; yp[counter] = y; counter++; } xMax = 0; xMin = 1000000; yMax = 0; yMin = 1000000; for(i = 0; i < xpoints.length; i++) { x = xp[i] * micronsPerPixel; y = yp[i] * micronsPerPixel; xpts[i] = x; ypts[i] = y; if(yMax < ypts[i]) yMax = ypts[i]; if(yMin > ypts[i]) yMin = ypts[i]; if(xMax < xpts[i]) xMax = xpts[i]; if(xMin > xpts[i]) xMin = xpts[i]; } yM = yMax; yMax = 0; yMin = 1000000; for(i = 0; i < ypts.length; i++) { ypts[i] = yM - ypts[i]; if(yMax < ypts[i]) yMax = ypts[i]; if(yMin > ypts[i]) yMin = ypts[i]; } if(checkData) { plotProgressXY(); if(checkResults) { setBatchMode(false); waitForUser("check plot"); } if(savePlot) { s = name1 + ".tif"; saveAs("Tiff", resultsDir + s); } } for(i = 0; i < xpts.length; i++) { x = replace(xpts[i], ".", ","); y = replace(ypts[i], ".", ","); print(x + "; " + y); } selectWindow("Log"); s = name1 + ".txt"; saveAs("Text", resultsDir + s); closeResults(); closeImage(); } function positionOfLargestParticle() { run("Set Measurements...", "area limit redirect=None decimal=8"); run("Analyze Particles...", "size=0-Infinity display clear record"); area = 0; pos = 0; n = nResults; for(i = 0; i < n; i++) { a = getResult("Area", i); if(a > area) { area = a; pos = i; } } return pos; } function plotProgressXY() { Plot.create("Profile XY", "X - µm", "Y - µm"); Plot.setLimits( 0, xMax, yMin, yMax); Plot.setLineWidth(1); Plot.setColor("red"); Plot.add("line", xpts, ypts); Plot.show(); } function closeImage() { while (nImages>0) { selectImage(nImages); close(); } } function closeResults() { if (isOpen("Results")) { selectWindow("Results"); run("Close"); } if (isOpen("ROI Manager")) { selectWindow("ROI Manager"); run("Close"); } if (isOpen("Log")) { selectWindow("Log"); run("Close"); } if (isOpen("Threshold")) { selectWindow("Threshold"); run("Close"); } if (isOpen("Debug")) { selectWindow("Debug"); run("Close"); } } macro "Close Images Tool - C00cT1f1aI" {} macro "Close Images Tool Options" { closeImage(); if (isOpen("ROI Manager")) {ClearRoiManager();} } macro "Close Results Tool - C00cT1f1aC" {} macro "Close Results Tool Options" { closeResults(); } ::DISCLAIMER:: This e-mail is confidential and intended for use by the addressee only. If you are not the intended recipient, please notify us immediately and delete this e-mail, as well as any attachment. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |