BIOP / qupath-extension-cellpose

an extension that wraps a Cellpose environment such that WSI can be analyzed using Cellpose through QuPath.
Apache License 2.0
63 stars 11 forks source link

different image ops for different channels ? #51

Closed NicoKiaru closed 1 month ago

NicoKiaru commented 2 months ago

Hi!

Is there a way to preprocess differently the channel 1 and channel 2 ? Are imageops applied identically to all channels ?

lacan commented 2 months ago

You can create two Transformed channel servers that each extract a given channel, apply the desired op and then recombine them into a third server that you pass on to cell pose, but all that needs to be done outside the builder

You then need to set the current image data to point to the new server you created.

You can see this post for inspiration https://forum.image.sc/t/specify-intensity-measurements-for-cellpose-extension-in-qupath/99814/2?u=oburri

NicoKiaru commented 2 months ago

Oui mon capitaine!

(Where I'm sttrugling is to go from an image server to a transformed image server where I apply a series of ImageOps. I'll dig and will find, but I'm going to do that in an IDE first: looking for the right way from scratch from groovy is a pain)

imagesc-bot commented 2 months ago

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

https://forum.image.sc/t/qupath-extract-two-channels-apply-two-different-series-of-imageop-then-reconstruct-an-imagedata/100965/1

lacan commented 1 month ago

A better solution is to use a SplitMerge op like in the example below

    sequentialOps = [ ImageOps.Core.splitMerge(
                          ImageOps.Core.sequential(
                              ImageOps.Channels.extract( myFirstChannel ),
                              ImageOps.Core.sqrt() // Keep appending more ops after extracting the channel(s)
                          ),
                          ImageOps.Core.sequential(
                              ImageOps.Channels.extract( mySecondChannel ), // Extract the other channel
                              ImageOps.Core.clip( 100,17000 ) // Keep appending more ops
                          ) // You can keep appending `sequential` ops that will make more channels in the end. Always extract the channel(s) first
                      )
                    ]
}
// the above will produce a 2 channel image for cellpose

def cellpose = Cellpose2D.builder( pathModel )
// Apply these ops and you can add any extra ops that you want to apply to all channels like usual
        .preprocess( *sequentialOps, ImageOps.Filters.gaussianBlur(3), ImageOps.Filters.median(2), ImageOps.Core.sqrt() )    
        ...