Giter Club home page Giter Club logo

Comments (3)

bkandel avatar bkandel commented on May 17, 2024

This is because the images are internally represented as pointers. Once
you close R and restart it, there's no way to recover where the pointer
points to. You will need to actually save the image as a Nifti (or
similar) and re-read from R.

On Fri, Dec 5, 2014 at 3:54 PM, dorianps [email protected] wrote:

I am having this issue all the time. AntsImages are unusuable if saved in
.R files and then reloaded.

For example, I load antsImages in workspace, save the workspace, and
reload it again later. What happens is that antsImages seem to be there,
but are compromised. If I try to use them R goes in segmentaiton fault.
There are two examples below, first I load an .R file, use mask from
within it and R crashes. Second I remove mask and reload it again, and all
works.
Is this a bug or antsImages S4 objects simply cannot be saved?

######################################
Welcome! Loading ANTsR...
ANTsR is loaded.

load(file="subjectdata.R")
mask
An object of class "antsImage"
Slot "pixeltype":
[1] "float"

Slot "dimension":
[1] 3

Slot "pointer":

ls()
[1] "imageList" "mask" "mydata" "thick" "workfolder"
mat<-imagesToMatrix(imageList, mask)

*** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
1: .Call("antsImage_RelationalOperators", e1, e2, region, operator,
PACKAGE = "ANTsR")
2: mask > 0
3: mask > 0
4: which(mask > 0)
5: imagesToMatrix(imageList, mask)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: q()
Selection: 3
#########################################
working example

Welcome! Loading ANTsR...
ANTsR is loaded.

load(file="subjectdata.R")
rm(mask)
mask<-antsImageRead('processing/smo_4_NormCortThick/mask.nii.gz', 3)
mat<-imagesToMatrix(imageList, mask)


Reply to this email directly or view it on GitHub
#7.

from antsr.

stnava avatar stnava commented on May 17, 2024

yes - ben is correct ... there is a way around this. if you convert the
image to an array, you can save ... but would have to reconvert back to an
image to use it as an image. there is probably a way to automate this
process and prevent this issue from happening: basically (optionally)
store the array within the ants image class. if the pointer is null then
reload the image from the array. maybe there is a better way, though.

brian

On Fri, Dec 5, 2014 at 3:59 PM, bkandel [email protected] wrote:

This is because the images are internally represented as pointers. Once
you close R and restart it, there's no way to recover where the pointer
points to. You will need to actually save the image as a Nifti (or
similar) and re-read from R.

On Fri, Dec 5, 2014 at 3:54 PM, dorianps [email protected]
wrote:

I am having this issue all the time. AntsImages are unusuable if saved
in
.R files and then reloaded.

For example, I load antsImages in workspace, save the workspace, and
reload it again later. What happens is that antsImages seem to be there,
but are compromised. If I try to use them R goes in segmentaiton fault.
There are two examples below, first I load an .R file, use mask from
within it and R crashes. Second I remove mask and reload it again, and
all
works.
Is this a bug or antsImages S4 objects simply cannot be saved?

######################################
Welcome! Loading ANTsR...
ANTsR is loaded.

load(file="subjectdata.R")
mask
An object of class "antsImage"
Slot "pixeltype":
[1] "float"

Slot "dimension":
[1] 3

Slot "pointer":

ls()
[1] "imageList" "mask" "mydata" "thick" "workfolder"
mat<-imagesToMatrix(imageList, mask)

*** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
1: .Call("antsImage_RelationalOperators", e1, e2, region, operator,
PACKAGE = "ANTsR")
2: mask > 0
3: mask > 0
4: which(mask > 0)
5: imagesToMatrix(imageList, mask)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: q()
Selection: 3
#########################################
working example

Welcome! Loading ANTsR...
ANTsR is loaded.

load(file="subjectdata.R")
rm(mask)
mask<-antsImageRead('processing/smo_4_NormCortThick/mask.nii.gz', 3)
mat<-imagesToMatrix(imageList, mask)


Reply to this email directly or view it on GitHub
#7.


Reply to this email directly or view it on GitHub
#7 (comment).

from antsr.

dorianps avatar dorianps commented on May 17, 2024

Thank you. I had the feeling this was the case.
This might confuse users. It would be great if there is a way to skip the saving of antsImages, or convert automatically to array, or perhaps show a notice that antsImages cannot be saved/loaded from data files. By the way, from what I understand these are regular S4 objects, it's weird that R itself is allowing to save pointers like any other data class.

Dorian

from antsr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.