Labeling and Visualization

visualization
cellprofiler
segmentation
help
trackobjects

#1

Hi,

I am new to CellProfiler and have a couple questions.

  1. A “TrackObjects” module is added to the end of the ExampleFlyImages pipeline (see below). By comparing the size of the nuclei and AreaShape in the spreadsheet, the ObjectNumber seems to match with the labels shown on the TrackObjects.
    Is it the right way to figure out the corresponding label of each nucleus (i.e. spreadsheet ObjectNumber)? Or in their a better way?

2a. I would like to display the contours of the nuclei and cytoplasm in different colors on top of the original image. Is there a way to do that?
2b. If I have multiple cell types, can I display their contours in different colors the same way (assuming that all cell are segmented and classified)?

Thank you!
Stephen


#2

Hi Stephen,

  1. TrackObjects_Label_(somenumber) will be the value in your spreadsheet that matches the numbers shown in the TrackObjects module window*- the (somenumber) part will match whatever you use as the maximum pixel distance
    2a) Yup! You’re looking for the OverlayOutlines module.
    2b) Yup again! You’ll want to either identify each cell type separately or identify them all and then use FilterObjects to create your different subpopulations- in any case, once you have the multiple object types that you want, you can use OverlayObjects to add the outlines of each in a different color.

Good luck!

*=Unless you use LAP tracking and run the second stage; things get complicated at that point, but no need to go into it unless you are actually doing that.


#3

For Question 1 (how do you associate ObjectNumber with objects in the image), I would use DisplayDataOnImage and choose the Object_Number, like this:

Then in the associated figure window, you will see each object labeled with its respective ObjectNumber.
No need for TrackObjects, IMHO.


#4

Ah, ty @David_Logan, I misunderstood the question.

David is right that you definitely don’t need to add TrackObjects just to get the labeled ObjectNumbers. DisplayDataOnImage will work as well, though unfortunately the output when you try to save it is a bit funny.

It’s worth pointing out also that even if you had no annotated images from CP at all the objects are numbered by 1) Center in Y Top->Bottom and 2) Center in X Left->Right, so you can generally figure out what part of the image to look in for Object 1 vs Object 30. If you need to confirm, each object’s XY center coordinates are reported so you could open the image in CP, ImageJ, etc, go to that location, and figure out which is which.


#5

Hi,

I received the following error while running CellProfiler’s
identifysecondaryobjects.
Does anyone know how to fix it? Thanks!

SystemError Traceback (most recent call
last) in ()----> 1 import
centrosome.propagate
~\Downloads\centrosome-1.0.4\centrosome\propagate.py in ()
1 import numpy as np 2 ----> 3 import _propagate 4 5
def propagate(image, labels, mask, weight):
~\Downloads\centrosome-1.0.4\centrosome_propagate.pyx in init
centrosome._propagate() 3 import_array() 4 ----> 5 import
numpy as np 6 import struct 7 cimport numpy as np
SystemError: Parent module ‘_propagate’ not loaded, cannot perform
relative import


#6

Hi,

Can you tell us a little more about what happened? CP version, OS, did you just update one or the other or clear out some system files, etc? Does this happen on all images or one image set in particular?


#7

My apology. I am not sure if this is a CellProfiler question and probably should have opened a new topic. Any help would be greatly appreciated!

I am trying to manipulate the identifysecondaryobjects function. As the function depends on centrosome.propagate, I am trying to install centrosome on my computer (64 bit window 10) using python 3.6.

Unfortunately, “pip3 install centrosome” keeps giving me the below error. I am just wondering if somebody knows how to fix this problem. Thank you!

Error message:

creating build\temp.win-amd64-3.6\Release\centrosome\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\appdata\local\programs\python\python36\lib\site-packages\numpy\core\include -Icentrosome/include -Ic:\users\appdata\local\programs\python\python36\include -Ic:\users\appdata\local\programs\python\python36\include “-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\8.1\include\shared” “-IC:\Program Files (x86)\Windows Kits\8.1\include\um” “-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt” /Tccentrosome/src/_cpmorphology.c /Fobuild\temp.win-amd64-3.6\Release\centrosome/src/_cpmorphology.obj
_cpmorphology.c
c:\users\appdata\local\programs\python\python36\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
centrosome/src/_cpmorphology.c(111): warning C4013: ‘PyInt_AsLong’ undefined; assuming extern returning int
centrosome/src/_cpmorphology.c(236): warning C4013: ‘PyString_FromString’ undefined; assuming extern returning int
centrosome/src/_cpmorphology.c(236): warning C4047: ‘=’: ‘PyObject *’ differs in levels of indirection from 'int’
centrosome/src/_cpmorphology.c(251): warning C4013: ‘Py_InitModule’ undefined; assuming extern returning int
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\users\appdata\local\programs\python\python36\libs /LIBPATH:c:\users\appdata\local\programs\python\python36\PCbuild\amd64 “/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64” /EXPORT:PyInit__cpmorphology build\temp.win-amd64-3.6\Release\centrosome/src/_cpmorphology.obj /OUT:build\lib.win-amd64-3.6_cpmorphology.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\centrosome/src_cpmorphology.cp36-win_amd64.lib
LINK : error LNK2001: unresolved external symbol PyInit__cpmorphology
build\temp.win-amd64-3.6\Release\centrosome/src_cpmorphology.cp36-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe’ failed with exit status 1120


Failed building wheel for centrosome
Running setup.py clean for centrosome
Failed to build centrosome
Installing collected packages: centrosome
Running setup.py install for centrosome … error
Complete output from command c:\users\appdata\local\programs\python\python36\python.exe -u -c “import setuptools, tokenize;file=‘C:\Users\AppData\Local\Temp\pip-build-wcvdsoka\centrosome\setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record C:\Users\AppData\Local\Temp\pip-lideiv5s-record\install-record.txt --single-version-externally-managed --compile:
Warning: Extension name ‘_propagate’ does not match fully qualified name ‘centrosome._propagate’ of 'centrosome/propagate.pyx’
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\centrosome
copying centrosome\bg_compensate.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\cpmorphology.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\fastemd.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\filter.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\haralick.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\index.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\kirsch.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\lapjv.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\mode.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\neighmovetrack.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\otsu.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\outline.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\princomp.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\propagate.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\radial_power_spectrum.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\rankorder.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\smooth.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\threshold.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\watershed.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome\zernike.py -> build\lib.win-amd64-3.6\centrosome
copying centrosome_init
.py -> build\lib.win-amd64-3.6\centrosome
running build_ext
building ‘_cpmorphology’ extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
creating build\temp.win-amd64-3.6\Release\centrosome
creating build\temp.win-amd64-3.6\Release\centrosome\src
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\appdata\local\programs\python\python36\lib\site-packages\numpy\core\include -Icentrosome/include -Ic:\users\appdata\local\programs\python\python36\include -Ic:\users\appdata\local\programs\python\python36\include “-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE” “-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt” “-IC:\Program Files (x86)\Windows Kits\8.1\include\shared” “-IC:\Program Files (x86)\Windows Kits\8.1\include\um” “-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt” /Tccentrosome/src/_cpmorphology.c /Fobuild\temp.win-amd64-3.6\Release\centrosome/src/_cpmorphology.obj
_cpmorphology.c
c:\users\appdata\local\programs\python\python36\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(12) : Warning Msg: Using deprecated NumPy API, disable it by #defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
centrosome/src/_cpmorphology.c(111): warning C4013: ‘PyInt_AsLong’ undefined; assuming extern returning int
centrosome/src/_cpmorphology.c(236): warning C4013: ‘PyString_FromString’ undefined; assuming extern returning int
centrosome/src/_cpmorphology.c(236): warning C4047: ‘=’: ‘PyObject *’ differs in levels of indirection from 'int’
centrosome/src/_cpmorphology.c(251): warning C4013: ‘Py_InitModule’ undefined; assuming extern returning int
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\users\appdata\local\programs\python\python36\libs /LIBPATH:c:\users\appdata\local\programs\python\python36\PCbuild\amd64 “/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64” “/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64” /EXPORT:PyInit__cpmorphology build\temp.win-amd64-3.6\Release\centrosome/src/_cpmorphology.obj /OUT:build\lib.win-amd64-3.6_cpmorphology.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\centrosome/src_cpmorphology.cp36-win_amd64.lib
LINK : error LNK2001: unresolved external symbol PyInit__cpmorphology
build\temp.win-amd64-3.6\Release\centrosome/src_cpmorphology.cp36-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command ‘C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe’ failed with exit status 1120


#8

I am trying to manipulate the identifysecondaryobjects function

As in, manipulate in the source code? Have you installed CP from source (perhaps following one of these sets of instructions)or did you install a pre-compiled build?

In any case, CP (and likely centrosome as well) is python 2, not python 3, so that may be why pip3 failed you. Without more information though about what you’re trying to do and why though, it’ll likely be hard to fix the over-arching problem.


#9

Thanks!

hmm…essentially, I want to get the output of identifysecondaryobjects directly as an array in python.

label_output = identifysecondaryobjects(some_input_images or mask)


#10

So you’re looking to call CellProfiler modules individually in like a python notebook or something? This can be done, but I’m afraid we don’t have a lot of documentation for it at the moment.

If you wanted a within-existing-CP workaround, by using ConvertObjectsToImage or just SaveImages in “Object” mode you can export the label matrix directly, then read it back into whatever your downstream workflow is (you’ll probably want to do this as a PNG or TIF; IIRC numpy arrays will be a file type option in 3.0).


#11

Thank you so much, Beth!