| import org.locationtech.jts.geom.util.GeometryCombiner |
| import org.locationtech.jts.operation.union.UnaryUnionOp |
|
|
| |
| int z = 0 |
| int t = 0 |
| def plane = ImagePlane.getPlane(z, t) |
| def objects = getAnnotationObjects() |
|
|
| |
| def amplada = 1024 |
| def alcada = 1024 |
| def solapament = 100 |
| def th_interseccio = 0.5 |
|
|
| |
| def original_ann = [] |
| def new_anns = [] |
| for (annotation in objects) { |
|
|
| print "Processing annotation " + annotation |
| roi = annotation.getROI() |
| if (roi.getClass() == qupath.lib.roi.RectangleROI){ |
| continue |
| } else { |
| |
| original_ann.add(annotation) |
| } |
| |
| x = roi.getBoundsX() |
| y = roi.getBoundsY() |
| h = roi.getBoundsHeight() |
| w = roi.getBoundsWidth() |
| |
| geom = roi.getGeometry() |
|
|
| |
| nh = Math.floor(w/(amplada-solapament)) |
| nv = Math.floor(h/(alcada-solapament)) |
| def count = 0 |
| |
| |
| for(int itx=0; itx <=nh; itx++){ |
| xc = x + itx*(amplada-solapament) - solapament/2 |
| for(int ity=0; ity <=nv; ity++){ |
| yc = y + ity*(alcada-solapament) - solapament/2 |
| def newroi = ROIs.createRectangleROI(xc, yc, amplada, alcada, plane) |
| def newannotation = PathObjects.createAnnotationObject(newroi) |
|
|
| |
| def newgeom = newroi.getGeometry() |
| combined=GeometryCombiner.combine([geom, newgeom]) |
| merged= UnaryUnionOp.union(combined) |
| mergedRois=GeometryTools.geometryToROI(merged, roi.getImagePlane()) |
| def intarea = (roi.getArea()+newroi.getArea() - mergedRois.getArea())/(amplada*alcada) // area de la interseccio |
|
|
| |
| if(intarea > th_interseccio){ |
| addObject(newannotation) |
| new_anns.add(newannotation) |
| count ++ |
| } |
| } |
| } |
| print 'Finnished processing annotation ' + annotation + ', ' + count + ' patchs generated.' |
| } |
|
|
| |
| removeObjects(original_ann, true) |
|
|
| |
| def imageData = getCurrentImageData().toString() |
| i = imageData.length()-6; |
| blanks=0; |
| name = '' |
| while (blanks<2 && i>=0) { |
| name = imageData[i] + name |
| i-- |
| if(imageData[i]==' '){ |
| blanks++ |
| } |
| } |
|
|
| |
| def path = "SET PATH HERE" |
|
|
| imageData = getCurrentImageData() |
| def server = imageData.getServer() |
|
|
| int i = 0 |
| aux = name |
| for (annotation in new_anns) { |
|
|
| roi = annotation.getROI() |
| x = roi.getBoundsX() |
| y = roi.getBoundsY() |
| h = roi.getBoundsHeight() |
| w = roi.getBoundsWidth() |
| |
| def request = RegionRequest.createInstance(imageData.getServerPath(), 1, roi) |
| |
| name = aux + ' (x=' + x + ', y=' + y + ', w=' + w + ', h=' + h + ').png' |
| |
| writeImageRegion(server, request, path + name) |
|
|
| i++ |
| } |
| |
| |
|
|
|
|
|
|