Installing wholebrain on Windows

Please open the video in a new window and follow along the instructions given in the video.
If you experience any problem go back and watch the youtube video carefully.
Below you find details on the installation steps.

Step-by-step walkthrough video showing Windows installation

Step 1. Install R on Windows.

Go to download R 3.3.3. . Click on the installation file.

I would suggest to enter custom settings and choose SDI instead of the default MDI, simply beacuse MDI is ugly and annoying.

MDI stands for multiple document interface (MDI) and is a graphical user interface in which multiple windows reside under a single parent window. SDI, single document interfaces, on the other hand is where all windows are independent of each other. Which provide much easier environment to work in when having multiple programs running.

Also if you like 'Matlab-ish' styled IDEs (integrated development environment), or new to R, then I would really recommend RStudio.

Step 2. Install Rtools.

RTools is a set of Unix-styled compilers that works with R on Windows.

Its needed for compiling STAN, OpenCV, and FFTW3.

Download the latest Rtools 3.3 and execute the installation file.

In the installation make sure to thick the option Add variables to path environment.
In the beginning it should read something akin to this (exact versions could differ):

c:\Rtools\bin;
c:\Rtools\gcc-4.6.3\bin;
C:\R\R-3.3.2\bin\x64;
...
C:\Program Files (x86)\CMake\bin;
C:\opencv\release\bin

If you do not know what a path environment variable is DO NOT simply copy paste this into the path environment since each path environment is unique to your computer and you might destroy paths for other programs you have installed, such as Matlab etc.

Step 3. Install STAN.

RStan will build automatically when you install WholeBrain from R however making sure that RStan works before you build opencv makes sure that your Rtools installation is working so we advice you test this if you get into problems.

Open up R and in the console enter the following command and press return:

Sys.setenv(MAKEFLAGS = "-j4") 

Then install Rstan with the following command entered into the console and press return:

install.packages("rstan", dependencies = TRUE)

Restart R.

Side note: Optional: try out if STAN is working:

Open up a new R session and run the following commands:

library(rstan)
model<-'data{
int N;
real y[N];
}
parameters{
real mu;
real sigma;
}
model{
y ~ normal(mu, sigma);
}'

model_data<- list( y = rnorm(10), N = 10  )

fit<-stan(model_code = model, data = model_data, iter = 4000, chains =4)

la<-extract(fit)

hist(la$mu)

If this works you should see a plot of the histogram from the generated posterior samples of mu.

Step 4. Install CMake.

Download the installer for Cmake. And run it. Select that you want CMake to add path variables.

Step 5. Install OpenCV.

Download the OpenCV 3.2.0 compressed library.

Lauch the downloaded the opencv-3.2.0.exe and extract the archive to a directory of your choice. I will be extracting directly to c:/ hence my opencv installation will be in c:/opencv/.

Download the OpenCVCompilerOptions.cmake file from here (2017-01-27 sorry link coming!), and replace the one that already exists under c:\opencv\sources\cmake. Alternatively you might just open the OpenCVCompilerOptions.cmake file in a text editor like notepad and search for the following code:

add_extra_compiler_option(-Werror=non-virtual-dtor)

and replace it with:

#add_extra_compiler_option(-Werror=non-virtual-dtor)

This is needed in order to suppress a warning that otherwise would terminate the building process when we compile using MinGW rather than the standard, but closed source, Microsoft Visual Studio compiler for Windows.

Once extracted open up CMake-GUI program.

In the input window labeled Where is the source code: enter:

c:/opencv/sources

or browse for your directory.

And in the input labeled as Where to build the binaries: enter:

c:/opencv/release

CMake will create the release directory automatically if you do not create it manually.

Then press configure. CMake will ask for you to set compilers. Chose Specify native compilers... then select from the pull down menu MinGW Makefiles press next and there set up compilers (make sure you are in mingw_64 directory and do not seelct 32 bit compilers in mingw_32 directory):

C compiler: c:/Rtools/mingw_64/bin/gcc.exe

C++ compiler: c:/Rtools/mingw_64/bin/g++.exe

You will get some errors and red highlighted text appears. Here you just need to specify the CMAKE_MAKE_PROGRAM
Specify it to point to mingw32-make.exe for me this is located under the:

c:/Rtools/mingw_64/bin/mingw32-make.exe

Again make sure you are in c:/Rtools/mingw_64/mingw32-make.exe and NOT c:/Rtools/mingw_32/mingw32-make.exe .

Press configure again. Now you should not get any errors but in search find BUILD_opencv_python2 as well as WITH_IPP and deselect them.

Press configure after delselecting BUILD_opencv_python2 and WITH_IPP. Then press generate.

Close CMake and open up a command prompt and go to the directory of the release by entering into the command prompt:

cd c:/opencv/release

Then start make by entering and press return:

mingw32-make

Once this is finished enter:

mingw32-make install

If you do not get any errors in the command prompt the installation of OpenCV was successful.

Step 6. Install FFTW3.

Download the FFT3 zip form here:
64-bit version: fftw-3.3.5-dll64.zip (3.1MB)

Extract the two files fftw3.h and libfftw3-3.dll into a new folder created under C:\ titled:
C:\fftw

And you're done installing FFTW3 on your computer.

Step 7. Set path variables.

In Windows click the "START" button and choose "Control Panel". Click on "System and Security".

Click on "System" (next to the icon with the computer). In the left tab you will se an option called "Advanced system setting"

This will open up a dialog window with the title "System Properties".
In the "Advanced" tab you will see a button at the bottom titled "Environmental variables...." click on it.

In the "System variables" panel click "New...". This will open up a dialog where you enter:
variable name: LIB_OPENCV
variable value: C:\opencv

We also want to add variable names for FFTW:
variable name: LIB_FFTW
variable value: C:\fftw

In the System variables panel scroll down and find the PATH variable and click "Edit...".
Be careful here and do not overwrite any existing information in the PATH variable value field. To be safe copy the all its content to a seperate notepad document and add
the following paths to both OpenCV and FFTW at the end of all other paths (paths are seperated by semicolon ;):
C:\opencv\release\install\x64\mingw\bin;C:\fftw

Step 8. Install WholeBrain.


if (!require(devtools)) {
  install.packages("devtools")
}
install.packages("rgl")
install.packages("grImport")
install.packages("knitr")
devtools::install_github("tractatus/wholebrain", args='--no-multiarch')

Step 9. Try wholebrian out.


library(wholebrain)
filename<-system.file('sample_tiles/rabiesEGFP.tif', package='wholebrain')
output<-segment(filename) 

IMPORTANT!!!! On Windows allways start your R session with the following line of code:


quartz<-function(width,height){windows(width, height)}

This is a temporary hack in order to make sure that Windows plots properly. Quartz is a really nice graphics layer by Apple that have no counter part in Windows. The following code makes sure that the Windows best substitute is used instead. We're examining what would be the best way forward on Windows to guarantee as nice figures as the ones Macintosh can deliver.