dahtah / imager

R package for image processing
GNU Lesser General Public License v3.0
187 stars 43 forks source link

Slicing through a list? #159

Closed mconsidine closed 2 years ago

mconsidine commented 2 years ago

I have a list of images, created like this SERframelist <- imlist() for (i in 1:FrameCount){ newframe <- readBin(SERfile,"integer",size=2,ImageWidth*ImageHeight, signed=FALSE,endian="little")/(2^16-1) newframe_cimg <- as.cimg(newframe, x=ImageWidth, y=ImageHeight, z=1, cc=NumberOfPlanes) SERframelist <- ci(SERframelist, newframe_cimg) } (As an aside, if there were a faster of way of reading a list of say 2000 images, I'd love to know it ...) length(SERframelist) returns 2180, which is the number of frames. What I now want to do is create an image that is the result of a slice through this "cube", if you can think of it that way. I try this tempimg <- as.cimg(SERframelist[[1:2180]][selectpt,bound1:bound2], x=2180,y=round(bound2)-round(bound1),z=1,cc=1) where "selectpt" is one of the columns of the frames and "bound1" and "bound2" are lower and upper bounds between which I want to select values. I want to take these 1-pixel slices and form a new image that is as wide as the number of frames and as high as bound2-bound1.

However, the above line generates this error Error in SERframelist[[1:2180]] : recursive indexing failed at level 2

Can anytone suggest how I can accomplish what I am trying to do or how I get around the error that's getting thrown?

Many thanks, mconsidine

ShotaOchi commented 2 years ago

You can ask google what is the meaning of the error message. You tried to access multiple indexes of list with double bracket but it was not allowed.

You can read the reference manual of imager. You can do it with imsub function and liply function.

mconsidine commented 2 years ago

Thanks for that reply. It was clear what was happening, but not why, given that it is allowed to access the image the way I presented it. Namely this plot(SERframelist[[1200]]) and this dim(SERframelist[[1200]]) and this SERframelist[[1200]][4,3] all give the expected results.

That said, your last line did help, with the solution being: bound1<- 24 bound2<- 974 selectpt<-50 slice.im <- function(im,y1=bound1,y2=bound2,x1=selectpt){imsub(im,y>=y1,y<=y2,x==x1) } temp <- liply(SERframelist,slice.im,"x") plot(as.cimg(temp)) dim(temp)

Thank you again.