jonclayden/RNiftyReg

Mask function working erradically

Closed this issue · 16 comments

Hi,
I am using the RniftyReg package to do register 2 images. I am trying to use the mask as a way to highlight the key area of the image I want used for the registration. I am getting error when I make a mask that is about 10% of the image. If I make the mask larger it seems to work. Is there some sort of limit on how many pixels must be active in the mask?

[NiftyReg ERROR] Function: initialise_block_matching_method()
[NiftyReg ERROR] There are no active blocks
Error in niftyreg.linear(source, target, scope, init, sourceMask, targetMask, :
[NiftyReg] Fatal error

Yes – from memory the block size is 4 pixels in each dimension, so the mask would need to cover at least that size.

I am bit confused. I am using images (source and target) of size (1800,2000,3). Then i try apply a mask on target like this and get the error:
maskUsed<-array(0,dim=c(1800,2000))
maskUsed[300:1800,300:2000]<-1
reg<-niftyreg(one,two,scope='rigid',targetMask = maskUsed,symmetric = TRUE)

[NiftyReg ERROR] Function: initialise_block_matching_method()
[NiftyReg ERROR] There are no active blocks
Error in niftyreg.linear(source, target, scope, init, sourceMask, targetMask, :
[NiftyReg] Fatal error

If i change my mask to the whole image being used as mask then it works.
maskUsed<-array(0,dim=c(1800,2000))
maskUsed[1:1800,1:2000]<-1
reg<-niftyreg(one,two,scope='rigid',targetMask = maskUsed,symmetric = TRUE)

Maybe i am misunderstanding the mask?
Thanks

Hmm, OK. It’s not obvious to me what’s going on here. Are you able to make your source and target images available so that I can give it a try?

I am not able to share the images that i am working with. So in theory this should be working right? That i can define a non-zero region in the image to use as my mask?

That’s the intent, yes. As long as there’s information in that region of the image (in particular, its intensity variance is not zero) it should be OK. Note also that, as your third dimension is 3, RNiftyReg will assume this is a three-channel image and average across channels before it starts the registration. Other than that, I’m afraid I don’t think I can help further without a reproducible example.

Ok. Let me try to replicate with shareable images. Have you tried this on images that you have?

Here is my example with images and code.
to send.zip

Thanks. I can reproduce the issue – I’m looking into it.

Phew, this issue took quite an effort to track down! I’ve pushed a commit to master which fixes it for me in your example - would you mind giving it a try on your original images, please?

Yes, you'll just need to pull the latest version of the package from GitHub. The easiest way to do that is with the remotes package:

install.packages("remotes")
remotes::install_github("jonclayden/RNiftyReg")

Ah, clearly you don’t have a suitable compiler toolchain installed. You could try the AppVeyor build at https://ci.appveyor.com/api/buildjobs/lll4lmofsg2sljtf/artifacts/RNiftyReg_2.6.7.zip, but if that doesn’t work or is too much hassle then I’ll just go ahead and push a release for you to try.

Sorry for the delay – recent events have obviously been quite disruptive. An updated version of the package, v2.6.8, is now on CRAN with the fix applied. Windows binary versions should appear there in the next day or two.

Closing this issue for now. Do reopen it if you see the problem recur.