Created
September 4, 2024 01:12
-
-
Save caner-ercan/ac0edcf34e738556ccc911c6abc04527 to your computer and use it in GitHub Desktop.
export points
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| resolveHierarchy() | |
| def server = getCurrentServer() | |
| tsv_folder = buildFilePath(PROJECT_BASE_DIR, "tsv") | |
| def checkDir = new File(tsv_folder) | |
| if(!checkDir.exists()) { | |
| checkDir.mkdir() | |
| } | |
| csv_folder = buildFilePath(PROJECT_BASE_DIR, "corrected_point") | |
| checkDir = new File(csv_folder) | |
| if(!checkDir.exists()) { | |
| checkDir.mkdir() | |
| } | |
| roi_folder = buildFilePath(PROJECT_BASE_DIR, "roi") | |
| checkDir = new File(roi_folder) | |
| if(!checkDir.exists()) { | |
| checkDir.mkdir() | |
| } | |
| name = getCurrentImageNameWithoutExtension() | |
| selectObjectsByClassification("annotation") | |
| anns = getSelectedObjects() | |
| for (int i = 0; i < anns.size(); i++) { | |
| def ann = anns[i] | |
| roi_name = name + '_' + i | |
| print roi_name | |
| //tile export | |
| def roi = ann.getROI() | |
| if(roi.getRoiName() != "Points"){ | |
| def requestROI = RegionRequest.createInstance(server.getPath(), 1, roi) | |
| def path = buildFilePath(roi_folder ,roi_name+".png") | |
| writeImageRegion(server, requestROI, path) | |
| //point export | |
| def points = ann.getChildObjects() | |
| for (point in points) { | |
| if(point.getROI().getRoiName() != "Points"){ | |
| points.remove(point) | |
| } | |
| File tsv_fileName = new File(buildFilePath(tsv_folder,roi_name+".tsv")) | |
| PointIO.writePoints(file = tsv_fileName, pathObjects = points) | |
| //coord correct | |
| def x = roi.getBoundsX() | |
| def y = roi.getBoundsY() | |
| def lines = tsv_fileName.readLines() | |
| def modifiedLines = [] | |
| for (int j = 0; j < lines.size(); j++) { | |
| // Split the line into an array of strings | |
| def columns = lines[j].split('\t') | |
| // If it's not the first line, modify the second and third columns | |
| if (j > 0) { | |
| columns[0] = (columns[0] as double) - (x as double) | |
| columns[1] = (columns[1] as double) - (y as double) | |
| } | |
| // Join the modified columns back into a string, using a comma as the separator | |
| modifiedLines.add(columns.join(',')) | |
| } | |
| def csv_file = new File(buildFilePath(csv_folder,roi_name+".csv")) | |
| csv_file.withWriter() { writer -> | |
| modifiedLines.each { line -> | |
| writer.writeLine(line) | |
| } | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment