Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ij.ImagePlus.getProcessor() error #53

Open
alicjamrzyglod opened this issue Oct 30, 2024 · 9 comments
Open

ij.ImagePlus.getProcessor() error #53

alicjamrzyglod opened this issue Oct 30, 2024 · 9 comments

Comments

@alicjamrzyglod
Copy link

Hi!
I've recently downloaded the most recent version of the qupath cellpose extension and run into an issue I am not able to solve. When I try to run the "detection script template" or "detect nuclei and cells using Cellpose.groovy" I get the following error:

ERROR: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null
java.lang.NullPointerException: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null
at qupath.ext.biop.cellpose.Cellpose2D.readObjectsFromTileFile(Cellpose2D.java:1365)
at qupath.ext.biop.cellpose.Cellpose2D.lambda$processCellposeFiles$18(Cellpose2D.java:790)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)

I am using brightfield WSI but also tried it out on a smaller tif with the same error.
I've noticed the same issue was posted in this forum https://forum.image.sc/t/cellpose-error-qupath-cannot-invoke-ij-imageplus-getprocessor/103845 very recently.

Any advice much appreciated!

@imagesc-bot
Copy link

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/cellpose-error-qupath-cannot-invoke-ij-imageplus-getprocessor/103845/2

@lacan
Copy link
Member

lacan commented Oct 31, 2024

Hi,
Could you tell me what version of cellpose you are using and where your QuPath project is stored? What computer architecture you are using?

The error seems to come from the fact that it cannot find the label image resulting from cellpose, so either cellpose did not run, the data is somewhere ImageJ's image opener cannot access, the file path is different from the one I expect or something else.

Best

Oli

@alicjamrzyglod1
Copy link

Hi Oli,
Thanks for the reply.
I am using cellpose version 3.1.0. on Windows 10 via python venv (python version 3.10.10). I stored my QuPath project on an external hard drive but have moved it now to local storage and made sure to move the images too. Unfortunately, I get the same error. Cellpose seems to be running as it creates a temp directory and I can see some greyscale tile output.

Best wishes,
Alicja

This is the script:

def pathModel = 'cyto3'
def stains = getCurrentImageData().getColorDeconvolutionStains() // stain deconvolution
def cellpose = Cellpose2D.builder( pathModel )
.pixelSize( 0.5 ) // Resolution for detection in um
// .channels( 'DAPI' ) // Select detection channel(s)
.preprocess( ImageOps.Channels.deconvolve(stains), ImageOps.Channels.extract(1) )
.tempDirectory( new File( '/tmp' ) ) // Temporary directory to export images to. defaults to 'cellpose-temp' inside the QuPath Project
// .preprocess( ImageOps.Filters.median( 1 ) ) // List of preprocessing ImageOps to run on the images before exporting them
// .normalizePercentilesGlobal( 0.1, 99.8, 10 ) // Convenience global percentile normalization. arguments are percentileMin, percentileMax, dowsample.
// .tileSize( 1024 ) // If your GPU can take it, make larger tiles to process fewer of them. Useful for Omnipose
// .cellposeChannels( 1,2 ) // Overwrites the logic of this plugin with these two values. These will be sent directly to --chan and --chan2
// .cellprobThreshold( 0.0 ) // Threshold for the mask detection, defaults to 0.0
// .flowThreshold( 0.4 ) // Threshold for the flows, defaults to 0.4
// .diameter( 15 ) // Median object diameter. Set to 0.0 for the bact_omni model or for automatic computation
// .useOmnipose() // Use omnipose instead
// .addParameter( "cluster" ) // Any parameter from cellpose or omnipose not available in the builder.
// .addParameter( "save_flows" ) // Any parameter from cellpose or omnipose not available in the builder.
// .addParameter( "anisotropy", "3" ) // Any parameter from cellpose or omnipose not available in the builder.
// .cellExpansion( 5.0 ) // Approximate cells based upon nucleus expansion
// .cellConstrainScale( 1.5 ) // Constrain cell expansion using nucleus size
// .classify( "My Detections" ) // PathClass to give newly created objects
// .measureShape() // Add shape measurements
// .measureIntensity() // Add cell measurements (in all compartments)
// .createAnnotations() // Make annotations instead of detections. This ignores cellExpansion
// .simplify( 0 ) // Simplification 1.6 by default, set to 0 to get the cellpose masks as precisely as possible
.build()

// Run detection for the selected objects
def imageData = getCurrentImageData()
def pathObjects = getSelectedObjects() // To process only selected annotations, useful while testing
// def pathObjects = getAnnotationObjects() // To process all annotations. For working in batch mode
if (pathObjects.isEmpty()) {
Dialogs.showErrorMessage( "Cellpose", "Please select a parent object!" )
return
}

cellpose.detectObjects( imageData, pathObjects )

// You could do some post-processing here, e.g. to remove objects that are too small, but it is usually better to
// do this in a separate script so you can see the results before deleting anything.
println 'Cellpose detection script done'

import qupath.ext.biop.cellpose.Cellpose2D

@woeuli
Copy link

woeuli commented Nov 21, 2024

Hi!

I get the exact same error when running the latest Cellpose version (conda) on QuPath-0.5.1-x64 on Mac when trying to segment hematoxylin images. It seems to create the tile but cannot process it, independent of file location.

ERROR: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null
java.lang.NullPointerException: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null

Any help on this topic is greatly appreciated!

Best
martin

Screen Shot 2024-11-21 at 15 22 45

@alicjamrzyglod
Copy link
Author

Hi!
I actually just fixed it the other day! The issue in my case was with python venv and my Windows username - I had an empty space in the username and because of this QuPath extension was not able to find the right python version. I created another Windows user on my PC with admin rights and reinstalled python 10 there then created another venv for cellpose and installed QuPath+extension. It works very well :)

Hope this helps!
Alicja

@woeuli
Copy link

woeuli commented Nov 22, 2024

Thanks for your quick reply! I re-installed and updated all the needed dependencies and conda environment and that also did the trick.
Happy image analyses!
martin

@vaioic
Copy link

vaioic commented Jan 7, 2025

I have suddenly encountered this same error. Working in Windows 11, QuPath v5.1, and CellPose extension v9.6. I was successfully running CellPose on three ROIs individually and then collectively. I then had the CellPose script generate annotations instead of detections. I wanted to test out the simplification parameter, so I deleted the annotations that were generated by CellPose while keeping the Rectangular ROIs and then set .simplify(2). After this change, I noticed the extension is grabbing the whole ROI as an image instead of generating tiles and then give this error:

ERROR: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null

I tried restarting QuPath, deleting the ROIs and drawing a new one, and deleting the cellpose-temp folder in the QuPath project folder. The same error occurred.

This is the set up for running CellPose (not including the lines after for simplification, they are identical to the script provided in the extension):

def pathModel = 'cyto3'
def cellpose = Cellpose2D.builder( pathModel )
        .pixelSize( 0.5 )                  // Resolution for detection in um
        .channels( 1 )	               // Select detection channel(s)
//        .tempDirectory( new File( '/tmp' ) ) // Temporary directory to export images to. defaults to 'cellpose-temp' inside the QuPath Project
//        .preprocess( ImageOps.Filters.median( 1 ) )                // List of preprocessing ImageOps to run on the images before exporting them
//        .normalizePercentilesGlobal( 0.1, 99.8, 10 ) // Convenience global percentile normalization. arguments are percentileMin, percentileMax, dowsample.
//        .tileSize( 1024 )                  // If your GPU can take it, make larger tiles to process fewer of them. Useful for Omnipose
//        .cellposeChannels( 1,2 )           // Overwrites the logic of this plugin with these two values. These will be sent directly to --chan and --chan2
//        .cellprobThreshold( 0.0 )          // Threshold for the mask detection, defaults to 0.0
//        .flowThreshold( 0.4 )              // Threshold for the flows, defaults to 0.4
        .diameter( 150 )                    // Median object diameter. Set to 0.0 for the `bact_omni` model or for automatic computation
//        .useOmnipose()                   // Use omnipose instead
//        .addParameter( "cluster" )         // Any parameter from cellpose or omnipose not available in the builder.
//        .addParameter( "save_flows" )      // Any parameter from cellpose or omnipose not available in the builder.
//        .addParameter( "anisotropy", "3" ) // Any parameter from cellpose or omnipose not available in the builder.
//        .cellExpansion( 5.0 )              // Approximate cells based upon nucleus expansion
//        .cellConstrainScale( 1.5 )         // Constrain cell expansion using nucleus size
//        .classify( "My Detections" )       // PathClass to give newly created objects
//        .measureShape()                  // Add shape measurements
//        .measureIntensity()              // Add cell measurements (in all compartments)
        .createAnnotations()             // Make annotations instead of detections. This ignores cellExpansion
        .simplify( 2 )                     // Simplification 1.6 by default, set to 0 to get the cellpose masks as precisely as possible
        .build()

This is what the log says:

INFO: Tile overlap was not set, but diameter exists. Using provided diameter 150.0 x 2: 300 pixels overlap
INFO: If tiling is necessary, 300 pixels overlap will be taken between tiles
INFO: Saving images for 1 tiles
INFO: Saving to E:\Pospisilik Lab\Josef\OIC-92_QuPathTrainingforSwissRollAnalysis\QuPath\cellpose-temp\Temp_24900_28237_z0_t0.tif
INFO: Executing command:
cmd.exe /C C:\Users\my.name\.conda\envs\cellpose\python.exe -Xutf8 -W ignore -m cellpose --dir "E:\Pospisilik Lab\Josef\OIC-92_QuPathTrainingforSwissRollAnalysis\QuPath\cellpose-temp" --pretrained_model cyto3 --diameter 150.0 --save_tif --no_npy --use_gpu --verbose
INFO: This command should run directly if copy-pasted into your shell
INFO: Virtual Environment Runner Started
INFO: Cellpose2D: Traceback (most recent call last):
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\runpy.py", line 194, in _run_module_as_main
INFO: Cellpose2D:     return _run_code(code, main_globals, None,
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\runpy.py", line 87, in _run_code
INFO: Cellpose2D:     exec(code, run_globals)
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\site-packages\cellpose\__main__.py", line 358, in <module>
INFO: Cellpose2D:     main()
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\site-packages\cellpose\__main__.py", line 65, in main
INFO: Cellpose2D:     logger, log_file = logger_setup()
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\site-packages\cellpose\io.py", line 60, in logger_setup
INFO: Cellpose2D:     handlers=[logging.FileHandler(log_file),
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\logging\__init__.py", line 1147, in __init__
INFO: Cellpose2D:     StreamHandler.__init__(self, self._open())
INFO: Cellpose2D:   File "C:\Users\kristin.gallik\.conda\envs\cellpose\lib\logging\__init__.py", line 1176, in _open
INFO: Cellpose2D:     return open(self.baseFilename, self.mode, encoding=self.encoding)
INFO: Cellpose2D: PermissionError: [Errno 13] Permission denied: 'C:\\Users\\kristin.gallik\\.cellpose\\run.log'
INFO: Cellpose2D: creating new log file
INFO: Reading Temp_24900_28237_z0_t0_cp_masks.tif
ERROR: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null
java.lang.NullPointerException: Cannot invoke "ij.ImagePlus.getProcessor()" because "label_imp" is null
    at qupath.ext.biop.cellpose.Cellpose2D.readObjectsFromTileFile(Cellpose2D.java:1365)
    at qupath.ext.biop.cellpose.Cellpose2D.lambda$processCellposeFiles$18(Cellpose2D.java:790)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
INFO: Cellpose detection script done
INFO: Total run time: 9.05 seconds

A very odd thing happened after more testing prior to posting. I specified the tile size and now the script will run. I then commented out the tile size parameter, deleted the cellpose-temp folder and reran the script and it worked again. I tried recreating the error following the same steps I did above but cannot recreate it.

I don't know if this is helpful or not, but it was very strange, and I do not know how it occurred or how I suddenly "fixed" it.

@NicoKiaru
Copy link
Member

deleted the cellpose-temp folder

Just a guess, maybe maybe there was some rights issues or files locked and erasing the folder was sufficient to fix issues ? Anyway, glad you had it fixed!

@bonniechatt
Copy link

I ran into this issue as well. The solution for me was to run the cellpose gui from command line once before running it through QuPath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants