Dear all especially the programming experts on this forum.
I had a former forum member who helped me out with the creation of a couple of plugins. Unfortunately I cannot reach him anymore for helping me out with a couple of changes I would like to make. So I try my luck on the forum if someone can help me. The plug ins made for me are still working fine, but one plug in I want to make some necessary changes. The plug in RoA_-1.jar is the plugin running now, the one I want to adjust, but the one I cannot open or see the code. I have also a macro file (WireCenter&Width_1h.ijm) from what I think was the last before the plugin was made, the source code is java I guess, but this one is also not running when I try it. I have no experience how to open, read and for sure not edit jar files, but I want start learning it from this example. I wanted send the working jar file and the macro before it was created into a plugin, but outlook blocked the jar file and the ijm file so I added the code below I hope someone can help me further. Thanks in advance, Martin. var topPos1, topPos2, lowPos1, lowPos2; var maxTW, maxBW, minTW, minBW; var maxTx, maxBx, minTx, minBx; var maxTy, maxBy, minTy, minBy; var maxTCy, maxBCy, minTCy, minBCy; var path, dir, resultsDir, name, list, name1; var wireDiam, neckDiam, imName, imCount, fudge = 10; var widthTop, widthBottom, wireW, neckW, convertScale; var topPos, cenPos, botPos, wireWidth, botNeck, topNeck; macro "Open Tool - C00cT1f1aO" {} macro "Open Tool Options" { setup(); setScale = true; imCount = 0; initializeResults(list.length); for (i=0; i<list.length; i++){ setBatchMode(true); if (!endsWith(list[i], "/")) { open (list[i]); if (setScale) scaleImage(); setScale = false; processImage(); closeImage(); imCount++; } } setResults(); setBatchMode(false); } function setResults() { run("Clear Results"); for(i = 0; i < imCount; i++) { setResult("Wire Diameter µm", i, wireDiam[i]); setResult("Neck Diameter µm", i, neckDiam[i]); setResult("Label", i, imName[i]); updateResults(); } selectWindow("Results"); saveAs("Results", resultsDir + "Results.xls"); } function initializeResults(len) { wireDiam = newArray(len); neckDiam = newArray(len); imName = newArray(len); } function scaleImage() { Dialog.create("Set Parameters"); Dialog.addNumber("enter scale in µm/pixel", 6.323); Dialog.addNumber("Change fudge to skip pixels", fudge); Dialog.show(); num = Dialog.getNumber(); fudge = Dialog.getNumber(); convertScale = num; inverse = 1/convertScale; print("scale = " + convertScale + " µm/pixel = " + inverse + " pixels/µm"); run("Set Scale...", "distance=1 known=" + num + " pixel=1 unit=µm global"); } function processImage() { topPos = newArray(getWidth()); cenPos = newArray(getWidth()); botPos = newArray(getWidth()); wireWidth = newArray(getWidth()); if(bitDepth() != 8) { run("8-bit"); } findLargestParticle(); setForegroundColor(255, 255, 255); run("Draw", "slice"); run("Select None"); resetThreshold(); x0 = 1; midline1 = getMidline(x0); x1 = getWidth() - 1; midline2 = getMidline(x1); drawLine(x0, midline1, x1, midline2); run("Invert"); run("Skeletonize"); run("Invert"); findWidths(); title = getTitle(); dot = lastIndexOf(title, "."); title1 = substring(title, 0, dot); saveAs("Tiff", resultsDir + title1); } 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 findLargestParticle() { setAutoThreshold("Default"); run("Set Measurements...", "area redirect=None decimal=2"); run("Analyze Particles...", "size=0-Infinity display clear record"); maxPart = 0; x1 = 0; y1 = 0; pos = 0; for(i = 0; i < nResults; i++) { area = getResult("Area", i); if(maxPart < area) { maxPart = area; x1 = getResult("XStart", i); y1 = getResult("YStart", i); pos = i; } } doWand(x1, y1); run("Colors...", "foreground=white background=black selection=yellow"); run("Clear Outside"); run("Clear", "slice"); } function findWidths() { counter = 0; for(x = 0; x < getWidth(); x++) { top = true; cen = false; bot = false; if(x > 0) { for(y = 0; y < getHeight(); y++) { pix = getPixel(x, y); if(pix == 255 && top) { topPos[x] = y; top = false; cen = true; counter = 0; } if(counter > fudge && pix == 255 && cen) { cenPos[x] = y; cen = false; bot = true; counter = 0; } if(counter > fudge && pix == 255 && bot) { botPos[x] = y; bot = false; counter = 0; } counter++; } wireWidth[x] = abs(botPos[x] - topPos[x]); } } wireW = getMode(wireWidth); wireWx = 0; topNeck = 1000000; botNeck = 1000000; tn = 0; tnx = 0; tny = 0; tcy = 0; bn = 0; bnx = 0; bny = 0; bcy = 0; wx = 0; wty = 0; wby = 0; go = true; for(x = 0; x < getWidth(); x++) { tn = abs(cenPos[x] - topPos[x]); bn = abs(botPos[x] - cenPos[x]); ww = abs(botPos[x] - topPos[x]); if(tn != 0 && tn < topNeck) { topNeck = tn; tnx = x; tny = topPos[x]; tcy = cenPos[x]; } if(bn != 0 && bn < botNeck) { botNeck = bn; bnx = x; bny = botPos[x]; bcy = cenPos[x]; } if(ww == wireW && go) { go = false; wx = x; wty = topPos[x]; wby = botPos[x]; } } title = getTitle(); wireDiam[imCount] = wireW * convertScale; neckDiam[imCount] = (botNeck + topNeck) * convertScale; imName[imCount] = title; print("*********** " + title + " ***********"); print("wire diameter: " + wireW * convertScale + " µm at " + wx * convertScale); print("top neck: " + topNeck * convertScale + " µm at " + tnx * convertScale); print("bottom neck: " + botNeck * convertScale + " µm at " + bnx * convertScale); print("neck: " + (botNeck + topNeck) * convertScale + " µm"); print("*********************************\n"); makeLine(wx, wty, wx, wby); run("Add Selection..."); makeLine(tnx, tny, tnx, tcy); run("Add Selection..."); makeLine(bnx, bny, bnx, bcy); run("Add Selection..."); run("Select None"); run("Overlay Options...", "stroke=red width=0 set apply show"); } function getMode(input) { returnVal = input[0]; repeatCount = 0; prevRepCnt = 0; for (i=0; i<input.length; i++) { for (j=i; j<input.length; j++) { if (i != j && input[i] == input[j]) { repeatCount++; if (repeatCount>=prevRepCnt) { returnVal=input[i]; } prevRepCnt = repeatCount; } repeatCount=0; } } return returnVal; } function getMidline(x) { counter = 0; top = true; bot = false; for(y = 0; y < getHeight(); y++) { pix = getPixel(x, y); if(pix == 255 && top) { topPos1 = y; top = false; bot = true; } else if(bot) counter++; if(counter > fudge && pix == 255 && bot) { lowPos1 = y; bot = false; midline = topPos1 + (lowPos1 - topPos1)/2; } } return midline; } 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 |
Dear Martin,
I will only answer your following question (since it is an easy one...): > I have no experience how to open, read and for sure not edit jar files, but I want start learning it from this example. As it is nicely explained within the following wiki file: https://en.wikipedia.org/wiki/JAR_(file_format) a jar file is typically "built on the ZIP format". Thus one easy way to open it, is to simply replace its extension from ".jar" to ".zip" and then open it with your preferred .zip opener software. And for the people who are Total commander (https://www.ghisler.com/) freaks (as I am) it is directly possible to open a jar file (i.e. without renaming it) with the Ctrl+PageDown key combination. Good luck for the other questions. My best regards, Philippe Philippe CARL Laboratoire de Bioimagerie et Pathologies UMR 7021 CNRS - Université de Strasbourg Faculté de Pharmacie 74 route du Rhin 67401 ILLKIRCH Tel : +33(0)3 68 85 41 84 -----Message d'origine----- De : ImageJ Interest Group [mailto:[hidden email]] De la part de Braekevelt Martin Envoyé : mercredi 6 mars 2019 09:38 À : [hidden email] Objet : edit a plugin Dear all especially the programming experts on this forum. I had a former forum member who helped me out with the creation of a couple of plugins. Unfortunately I cannot reach him anymore for helping me out with a couple of changes I would like to make. So I try my luck on the forum if someone can help me. The plug ins made for me are still working fine, but one plug in I want to make some necessary changes. The plug in RoA_-1.jar is the plugin running now, the one I want to adjust, but the one I cannot open or see the code. I have also a macro file (WireCenter&Width_1h.ijm) from what I think was the last before the plugin was made, the source code is java I guess, but this one is also not running when I try it. I have no experience how to open, read and for sure not edit jar files, but I want start learning it from this example. I wanted send the working jar file and the macro before it was created into a plugin, but outlook blocked the jar file and the ijm file so I added the code below I hope someone can help me further. Thanks in advance, Martin. var topPos1, topPos2, lowPos1, lowPos2; var maxTW, maxBW, minTW, minBW; var maxTx, maxBx, minTx, minBx; var maxTy, maxBy, minTy, minBy; var maxTCy, maxBCy, minTCy, minBCy; var path, dir, resultsDir, name, list, name1; var wireDiam, neckDiam, imName, imCount, fudge = 10; var widthTop, widthBottom, wireW, neckW, convertScale; var topPos, cenPos, botPos, wireWidth, botNeck, topNeck; macro "Open Tool - C00cT1f1aO" {} macro "Open Tool Options" { setup(); setScale = true; imCount = 0; initializeResults(list.length); for (i=0; i<list.length; i++){ setBatchMode(true); if (!endsWith(list[i], "/")) { open (list[i]); if (setScale) scaleImage(); setScale = false; processImage(); closeImage(); imCount++; } } setResults(); setBatchMode(false); } function setResults() { run("Clear Results"); for(i = 0; i < imCount; i++) { setResult("Wire Diameter µm", i, wireDiam[i]); setResult("Neck Diameter µm", i, neckDiam[i]); setResult("Label", i, imName[i]); updateResults(); } selectWindow("Results"); saveAs("Results", resultsDir + "Results.xls"); } function initializeResults(len) { wireDiam = newArray(len); neckDiam = newArray(len); imName = newArray(len); } function scaleImage() { Dialog.create("Set Parameters"); Dialog.addNumber("enter scale in µm/pixel", 6.323); Dialog.addNumber("Change fudge to skip pixels", fudge); Dialog.show(); num = Dialog.getNumber(); fudge = Dialog.getNumber(); convertScale = num; inverse = 1/convertScale; print("scale = " + convertScale + " µm/pixel = " + inverse + " pixels/µm"); run("Set Scale...", "distance=1 known=" + num + " pixel=1 unit=µm global"); } function processImage() { topPos = newArray(getWidth()); cenPos = newArray(getWidth()); botPos = newArray(getWidth()); wireWidth = newArray(getWidth()); if(bitDepth() != 8) { run("8-bit"); } findLargestParticle(); setForegroundColor(255, 255, 255); run("Draw", "slice"); run("Select None"); resetThreshold(); x0 = 1; midline1 = getMidline(x0); x1 = getWidth() - 1; midline2 = getMidline(x1); drawLine(x0, midline1, x1, midline2); run("Invert"); run("Skeletonize"); run("Invert"); findWidths(); title = getTitle(); dot = lastIndexOf(title, "."); title1 = substring(title, 0, dot); saveAs("Tiff", resultsDir + title1); } 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 findLargestParticle() { setAutoThreshold("Default"); run("Set Measurements...", "area redirect=None decimal=2"); run("Analyze Particles...", "size=0-Infinity display clear record"); maxPart = 0; x1 = 0; y1 = 0; pos = 0; for(i = 0; i < nResults; i++) { area = getResult("Area", i); if(maxPart < area) { maxPart = area; x1 = getResult("XStart", i); y1 = getResult("YStart", i); pos = i; } } doWand(x1, y1); run("Colors...", "foreground=white background=black selection=yellow"); run("Clear Outside"); run("Clear", "slice"); } function findWidths() { counter = 0; for(x = 0; x < getWidth(); x++) { top = true; cen = false; bot = false; if(x > 0) { for(y = 0; y < getHeight(); y++) { pix = getPixel(x, y); if(pix == 255 && top) { topPos[x] = y; top = false; cen = true; counter = 0; } if(counter > fudge && pix == 255 && cen) { cenPos[x] = y; cen = false; bot = true; counter = 0; } if(counter > fudge && pix == 255 && bot) { botPos[x] = y; bot = false; counter = 0; } counter++; } wireWidth[x] = abs(botPos[x] - topPos[x]); } } wireW = getMode(wireWidth); wireWx = 0; topNeck = 1000000; botNeck = 1000000; tn = 0; tnx = 0; tny = 0; tcy = 0; bn = 0; bnx = 0; bny = 0; bcy = 0; wx = 0; wty = 0; wby = 0; go = true; for(x = 0; x < getWidth(); x++) { tn = abs(cenPos[x] - topPos[x]); bn = abs(botPos[x] - cenPos[x]); ww = abs(botPos[x] - topPos[x]); if(tn != 0 && tn < topNeck) { topNeck = tn; tnx = x; tny = topPos[x]; tcy = cenPos[x]; } if(bn != 0 && bn < botNeck) { botNeck = bn; bnx = x; bny = botPos[x]; bcy = cenPos[x]; } if(ww == wireW && go) { go = false; wx = x; wty = topPos[x]; wby = botPos[x]; } } title = getTitle(); wireDiam[imCount] = wireW * convertScale; neckDiam[imCount] = (botNeck + topNeck) * convertScale; imName[imCount] = title; print("*********** " + title + " ***********"); print("wire diameter: " + wireW * convertScale + " µm at " + wx * convertScale); print("top neck: " + topNeck * convertScale + " µm at " + tnx * convertScale); print("bottom neck: " + botNeck * convertScale + " µm at " + bnx * convertScale); print("neck: " + (botNeck + topNeck) * convertScale + " µm"); print("*********************************\n"); makeLine(wx, wty, wx, wby); run("Add Selection..."); makeLine(tnx, tny, tnx, tcy); run("Add Selection..."); makeLine(bnx, bny, bnx, bcy); run("Add Selection..."); run("Select None"); run("Overlay Options...", "stroke=red width=0 set apply show"); } function getMode(input) { returnVal = input[0]; repeatCount = 0; prevRepCnt = 0; for (i=0; i<input.length; i++) { for (j=i; j<input.length; j++) { if (i != j && input[i] == input[j]) { repeatCount++; if (repeatCount>=prevRepCnt) { returnVal=input[i]; } prevRepCnt = repeatCount; } repeatCount=0; } } return returnVal; } function getMidline(x) { counter = 0; top = true; bot = false; for(y = 0; y < getHeight(); y++) { pix = getPixel(x, y); if(pix == 255 && top) { topPos1 = y; top = false; bot = true; } else if(bot) counter++; if(counter > fudge && pix == 255 && bot) { lowPos1 = y; bot = false; midline = topPos1 + (lowPos1 - topPos1)/2; } } return midline; } 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |