I have 2 3D grayscale images of equal dimensions.
The first image (img) is the raw data of a 3D volume (obtained using a microscope) and contains various cells. Example slice of raw 3d image
The second image (imglab) is a masked version of the raw image where each identified cell is filled with a single, unique value (i.e. cell 1 = all 1s, cell 2 = all 2s). All non cell regions are zeros. Example slice of masked 3d image
I am now trying to find the coordinates of the maximum value of each cell from the raw data that corresponds to the labeled mask array.
Currently, I have a loop which is extremely inefficient. I suspect there is a way to setup multiple conditions using a single np.where call, but I can't figure out how to do this. The current for loop method is below:
coordinates = []
for i in range(1, int(imglab.max())): # Number of cells = max value of label image
max_val = np.max(img[imglab == i])
max_coord = np.where((img == max_val) & (imglab == i))
coordinates.append(max_coord)