How do I apply an identical TMA Dearray operation on an image and its binary mask form?

Mask and Raw Image


I have been given TMA data as well as masks marking the position of nuclei within the cores. I have used TMA dearrayer to split the cores into independent .jpg files, but would also like to generate identical splits on the mask version of the image. Therefore, I should have raw images and the corresponding masks, ready for training a network.


In order to do this, I saved the output of “Show TMA Measurements” and also used “FIle → TMA Data → Export TMA Data” to store the relevant data of the cores from the original .svs image e.g. Centroid X and Y values. I then opened the .tiff mask image, created a “full image annotation (Objects->Annotations)” and used the code below (provided by Pete Bankhead) to create a grid of the same dimensions as that of the original image. I then tried to “Import TMA data” so that the positions of my created cores would now match the cores from the original images. Unfortunately, this doesn’t work as I keep seeing a message box saying " 0 Cores updated" .

import qupath.lib.objects.PathObjects
import qupath.lib.objects.hierarchy.DefaultTMAGrid

// Enter the number of horizontal & vertical cores here
int numHorizontal = 13
int numVertical = 8
// Enter the core diameter, in millimetres
double diameterMM = 2

// Convert diameter to pixels
double diameterPixels = (diameterMM * 1000) / getCurrentImageData().getServer().getPixelCalibration().getAveragedPixelSizeMicrons()

// Get the current ROI
def roi = getSelectedROI()

// Create the cores
def cores = []
double xSpacing = roi.getBoundsWidth() / numHorizontal
double ySpacing = roi.getBoundsHeight() / numVertical
for (int i = 0; i < numVertical; i++) {
        for (int j = 0; j < numHorizontal; j++) {
        double x = roi.getBoundsX() + xSpacing / 2 + xSpacing * j
        double y = roi.getBoundsY() + ySpacing / 2 + ySpacing * i
        cores << PathObjects.createTMACoreObject(x, y, diameterPixels, false)

// Create & set the grid
def tmaGrid = new DefaultTMAGrid(cores, numHorizontal)
relabelTMAGrid("1-13","A-H", true)

Just to check, there is no command that I know of called Import TMA Data - There is an Import TMA Map, though that is to add metadata to existing cores as shown in Pete’s TMA video:

It sounds like what you want to do is something more akin to an affine transformation to move objects from one image to another image of a different size?

Hi, sorry only time for a quick answer here – would simply copying the data file for the dearrayed TMA to the mask image work?

Assuming both images are in a QuPath project, right-click on the dearrayed image in the ‘Project’ tab and choose Open directory… → Project entry from the popup menu. You should find a file called data.qpdata. You can then copy this to the corresponding directory of the mask image.

(If this doesn’t solve the right problem, feel free to disregard it – I might have read the question too quickly :slight_smile: )


Right, if the images are the exact same pixel size, that would be even easier!

*Yep, the magnifications were what I noticed as well…

Ah yes, looks from the magnifications that they might not be (?), and if using Linux opening the directories might not work… if it fails, it should just copy the path of the directory to the clipboard instead.

1 Like

Many thanks! This did the job.

Small follow up:

I can’t seem to remove the effect of the image going from white to black as you go from left to right. However, as I zoom into the black regions, they become white like the core in the top left corner. This is why I have circles on the top row even though it looks like there’s nothing there. The issue is that when I save the cores attained through TMA dearraying, it saves them from this perspective. This means the cores from the first row are just black squares. If I were to zoom into the top row though, I can see the cores as clearly as the one in the top left. I have tried the other options on the “Brightness & Contrast” page but no luck.

Do you know to remove this effect? Or get TMA Dearrayer to ignore it?

Hi @EngEmmanuel, my guess is you’re using Ubuntu – in which case it is probably the pixman bug.

The easiest solution I know is to use the launch script I posted here: