tractatus / wholebrain

R package for segmentation, registration and generating web-based brain atlases from microscope images
GNU General Public License v3.0
82 stars 42 forks source link

quartz dependency, useless on linux #3

Closed kohlkopf closed 6 years ago

kohlkopf commented 6 years ago

In the tutorial, you call quartz() followed by the registration() function. Within registration(), quartz() is called several times. You do have a conditional statement check for the Windows OS .Platform$OS.type=="windows", however there is no check for linux. The Quartz graphical layer is the macOS graphics model. It does not and can not be run on linux. There is no call to x11() in your code.

We are running the package on a linux machine and forwarding the graphics over SSH with X11, could this have any effect? We are able to get though the tutorial up until the registration step.

tractatus commented 6 years ago

Hi @kohlkopf

Glad to hear that you are using WholeBrain and really nice that you report issues here.

Most likely if you are running on linux server with SSH you wouldn't plot, setting display to FALSE, and rather make a pipeline and sink output using makewebmap() for each section into a static HTML file and folder to be viewed in your browser from another machine.

However, you are right in that the code doesn't check for Linux OS. Thanks for pointing that out. I've changed that and pushed this. Let me know if there are any device specific issues such as images rendering upside down etc.

Update wholebrain to latest version either by using:

update.wholebrain()

Or manually:

detach("package:wholebrain", unload = TRUE) remove.packages("wholebrain")

R might or might not require reboot before you install again depending on OS: devtools::install_github("tractatus/wholebrain")

If installation was successful you should see:

WholeBrain (version 0.1.1) "Thurstone" \n by Daniel Fürth, 2018

With 0.1.1 being the latest version with this change.

Happy mapping!

kohlkopf commented 6 years ago

Thanks for the quick response! We have updated and are successfully running version 0.1.1 on a linux machine with X11 forwarding to a macOS . We are now running in to a new issue. I can't tell if this is due to the OpenCV or wholebrain. Do you have any ideas?

> regi<-registration(FFC_filename, coordinate=0.38, filter=seg$filter)
Loading image:/l/Yu/YuLab/Bioinformatics/projects/wholebrain/stitched_FFC_section001/stitched_FFC_section001.tif
====== LOADING DONE ======
Resizing to: 0% of original size.
Image type: CV_16U_2
OpenCV(3.4.1) Error: Assertion failed (dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0)) in resize, file /src/opencv-3.4.1/modules/imgproc/src/resize.cpp, line 4045
Error in get.contour(file, thresh = brain.threshold, resize = resize,  : 
  OpenCV(3.4.1) /src/opencv-3.4.1/modules/imgproc/src/resize.cpp:4045: error: (-215) dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0) in function resize
tractatus commented 6 years ago

Could you run:

edit(seg$filter)

And post output here. Looks like something is off with the filter parameters.

kohlkopf commented 6 years ago

Sorry @tractatus, I'm unable to reproduce the error. Still running linux machine and forwarding the graphics over SSH with X11 with the main tutorial. I have a new one however! After adjusting the parameter during the segmentation step and escaping the window, I receive and X11() error. I wonder it might be an argument was left out in a function call? We are running the wholebrain package locally on MacOS and it produces some beautiful results.

Loading image:/l/Yu/YuLab/Bioinformatics/projects/wholebrain/stitched_FFC_section001/stitched_FFC_section001.tif
LOADED. loading took 5 seconds.
Image type: CV_16U_2
Changed image type to: CV_16S_3
Controls:
ESC or Q key: exit segmentation and output results.
H key: hide/display segmentation overlay.
Z key: hide zoom window.
Resizing to: 25% of original size.

Assembling output list

OUTPUT SEGMENTED CELLS: 785
Error in X11(width, height) : 
  argument "width" is missing, with no default
>
tractatus commented 6 years ago

Hi @kohlkopf you need to post the code what you are doing.

Also please post the output of:

edit(seg$filter)

Since your error with registration() seems to be you never actually did segmentation of the brain outline. Have you gone through the tutorial?

The error says something with X11 but you're output looks like you were calling segment() which should have no reference to X11() or any other plotting device. The error form X11() has to come form something you are calling after segment(). So please post the code and not only your output.

kohlkopf commented 6 years ago

The code from tutorial_single_section.R, up until it breaks:

library(wholebrain)

#set folder path
folder<-'/l/Yu/YuLab/Bioinformatics/projects/wholebrain/section001'

#find out how many images we have and their location
images<-get.images(folder)
length(images)

#stitch this image
get.grid.coordinates(1:length(images), tilesize=2048, plotgrid=TRUE)

stitch(folder, show.image=TRUE)

#image show command
filename<-'/l/Yu/YuLab/Bioinformatics/projects/wholebrain/stitched_section001/stitched_section001.tif'

imshow(filename)

#flat-field correction
flat.field.correction(folder)
FFC_folder<-'./FFC_section001'
stitch(FFC_folder)

FFC_filename<-'/l/Yu/YuLab/Bioinformatics/projects/wholebrain/stitched_FFC_section001/stitched_FFC_section001.tif'
imshow(FFC_filename)

#Segmentation
seg<-segment(FFC_filename)

edit(seg$filter):

structure(list(c(12, 113), c(6193L, 20719L), 999L, 11935, 0,
    788L, 0.0292, 2L, 0.25), .Names = c("alim", "threshold.range",
"eccentricity", "Max", "Min", "brain.threshold", "resize", "blur",
"downsample"))

names(seg)
names(seg$soma)
plot(seg$soma$x, seg$soma$y, ylim=rev(range(seg$soma$y)), asp=1)
tractatus commented 6 years ago

For this error: Error in X11(width, height) : argument "width" is missing, with no default

It still seems to not be fatal but actually give you segmentation results. It seems this is related to x11 being called from OpenCV and not R. So this entirely depends on how you compiled opencv. Malcolm, also from Stowers Institute, emailed me and had some issue with GTK and opencv compilation. Was this resolved? I would compile OpenCV without any frameworks such as GTK or Qt if possible.

But since it is not fatal and you are able to do segmentation is this really an error? Or is it that the x11() error interrupts R script hindering you from processes an entire script?

For the error you get during registration:

> regi<-registration(FFC_filename, coordinate=0.38, filter=seg$filter)
Loading image:/l/Yu/YuLab/Bioinformatics/projects/wholebrain/stitched_FFC_section001/stitched_FFC_section001.tif
====== LOADING DONE ======
Resizing to: 0% of original size.
Image type: CV_16U_2
OpenCV(3.4.1) Error: Assertion failed (dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0)) in resize, file /src/opencv-3.4.1/modules/imgproc/src/resize.cpp, line 4045
Error in get.contour(file, thresh = brain.threshold, resize = resize,  : 
  OpenCV(3.4.1) /src/opencv-3.4.1/modules/imgproc/src/resize.cpp:4045: error: (-215) dsize.area() > 0 || (inv_scale_x > 0 && inv_scale_y > 0) in function resize

You can see the issue here: Resizing to: 0% of original size.

Your resizing parameter is 0, OpenCV then complains that you are trying to resize your image to 0 which is impossible. So probably resize was never set since default would 0. The code you later show with edit(seg$filter) indicates that you did set it so should work after that.

For servers you usually just make a pipeline with set filters and use them like this:

myfilter<-structure(list(c(12, 113), c(6193L, 20719L), 999L, 11935, 0,
    788L, 0.0292, 2L, 0.25), .Names = c("alim", "threshold.range",
"eccentricity", "Max", "Min", "brain.threshold", "resize", "blur",
"downsample"))

seg<-segment(FFC_filename, filter = myfilter)

Also loading time with 5 seconds seems to be really slow. For an image with 500 Mb size it should take less than 0.5-1 seconds depending on if SSD is used. So looks like you are calling image paths over the network. If tons of images are processed better to transfer them to SSD before using segment() or registration().

kohlkopf commented 6 years ago

Running the script line by line on a local disk on the linux server I am able to get to the registration step. I realized (using your parameters in the tutorial) I am unable to produce the brain outline--is there any way to confirm that this is being found and simply not showing?

Loading image:./stitched_FFC_section001/stitched_FFC_section001.tif
====== LOADING DONE ======
Resizing to: 0.0428% of original size.
Image type: CV_16U_2
OpenCV(3.4.1) Error: Assertion failed (src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3))) in threshold, file /src/opencv-3.4.1/modules/imgproc/src/thresh.cpp, line 1406
Error in get.contour(file, thresh = brain.threshold, resize = resize,  : 
  OpenCV(3.4.1) /src/opencv-3.4.1/modules/imgproc/src/thresh.cpp:1406: error: (-215) src.type() == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3)) in function threshold

As I spend more time with the software this looks like I simply could not establish the brain outline. If so it looks like you've fixed the original issue and I've found a new one, I can raise a new issue if you want to close this one.

Interestingly, when I manually enter the filter it does not fail (as you predicted). The images are flipped about the horizontal axis in the registration step however. screen shot 2018-08-02 at 4 39 39 pm

tractatus commented 6 years ago

I don't think you should raise any issues here on Github since this is not issues but rather you getting started with the software. There is an entire FAQ in the website for this.

For casually asking short questions and tips use Gitter I usually try to get back to you within a couple of minutes if it is a straightforward thing: https://gitter.im/tractatus/Lobby

Github should preferably be about code errors and restricted to single issues that can be tractable such as the raster image being upside down above. Thanks for pointing that out. That is OS specific I've changed and pushed so you can update.

Please be more specific what you mean with "using your parameters in the tutorial" post the parameters obtained fromseg$filter. The previous one you posted is set to 0 which you probably should not have and indicates it was never set. Something like 900 is probably what you want for that image.

For manually inspecting brain outline check this part in the video: https://youtu.be/ZLnNlcKlRdM?t=18m5s

kohlkopf commented 6 years ago

The above two were code errors. I was asking whether you wanted to keep the Github issues more organized by keeping one problem per issue. The flipped images should probably have been a separate issue since you fixed the original lack of X11() but I suppose it's related to the X11() issue.

Using the previously posted filter the brain outline is 799L, not 0. No outline shows up.

Thanks for the quick replies and quick updates!