dahtah / imager

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

as.data.frame on image lists #52

Closed aCaB closed 7 years ago

aCaB commented 7 years ago

Hi, I'm having trouble applying as.data.frame to image lists such as the one returned by imgradient("xy"):

> gr <- imgradient(grayscale(boats),"xy")
> range(as.data.frame(gr[['x']])$x)
[1]   1 256
> range(as.data.frame(gr)$x)
[1] -0.5  0.5
Warning messages:
1: In if (standardise) { :
  the condition has length > 1 and only the first element will be used
2: In if (standardise) { :
  the condition has length > 1 and only the first element will be used

On a single image, as.data.frame maintains the original coordinates of the boats image. However, on an image list, as.data.frame produces the above warning and updates the x,y tuples

I'm not sure if the rescale is intended but this has practical consequences: for example the Plotting a gradient field code relies on x and y being integers:

##Subsample: take every fourth pixel
dgr.sub <- dplyr::filter(dgr,(x %% 4) ==0,(y %% 4) == 0)

Sorry if I'm missing something and thanks for the amazing package!

> packageVersion("imager")
[1] '0.40.2'
dahtah commented 7 years ago

That's indeed a bug, thanks for reporting it! I've updated the master branch with a fix. You can use devtools::install_github to update.

aCaB commented 7 years ago

I confirm eff74774ab531941fe45da2afd1a3bd347f3ded2 fixes the problem.

Thank you