Flask: Efficient on-demand delivery of selected 2D slices from 3D volumes - html

How can I efficiently store hundreds of 3D volumes and serve selected instance slices on-demand with Flask?
I am currently solving the issue by saving each subvolume as an image collection of its slices. Here each folder is a subvolume (cropped out object) - the image names correspond to the slices of the volume from which the subvolume was cropped.
├── 1/
│ ├── 1.png
| ...
│ ├── 10.png
│ └── 11.png
├── 2/
│ ├── 0.png
| ...
│ ├── 4.png
│ └── 5.png
├── 3/
│ ├── 3.png
| ...
│ ├── 11.png
│ └── 12.png
...
|
└── 176/
├── 34.png
...
├── 43.png
└── 44.png
Instead, I would like to store each subvolume, e.g., as a single tiff file and only serve the required slices.
├── 1/
│ └── image.tif
├── 2/
│ └── image.tif
├── 3/
│ └── image.tif
...
|
└── 176/
└── image.tif
However, according to this Stackoverflow answer the only mainstream browser that supports tiff is Safari.
Is there a way where I don't have to save every single image? Especially considering that I will only need to depict the most centric slice of a subvolume in most cases and only in a few cases make the whole subvolume browsable.

Related

Import and convert module into qtdesign

I would like to integrate the python modules (in the algo/ folder) into the main program that uses an interface_ui is created by QT designer.
This is my folder structure.
├── algo/
│ └── main_algo.py
│ └── a.py
│ └── b.py
│ └── read_data.py
│ └── data/
│ └── data.bin
└── main.py
└── interface_ui.py
Note that the main_algo.py will import a.py, b.py, and read_data.py (function to read data.bin)
So, I have two solutions:
I have created a button in the interface and executed the function main_algo.py each time I push the button
exec(open("path/main_algo.py.py").read())
I would convert all the modules inside the algo/ folder into the function and call back the function in the main.py whenever I want.
import sys
sys.path.insert(1,"path_to_algo/")
from a import x,y
from b import z
import read_data
Please tell me the advantages of each solutions and how can we do the second solution.
Thank you very much

finding path in HTML

My file is organized like this:
My/
├── public/
│ ├── css/
│ │ ├── sign.css
├── views/
│ ├── register.ejs
And I typed in below to access the "sign.css" file:
<link href="css/sign.css" rel="stylesheet">
Why is the href path correct?
Shouldn't it be ../public/css/sign.css
since in order to access sign.css, the step is
"go back one file to My -> go into public -> go into css -> access sing.css"?
app.use(express.static('public'))
Above code sets public directory from which to serve static assets.
Express looks up the files relative to the static directory, so the name of the static directory is not part of the URL.

Gulp minify and move files with same folder structure

I have a folder structure like this:
.
├── dist/
└── src/
├── index.php
└── projects/
├── some-project/
│ ├── main.css
│ ├── main.js
│ └── index.html
└── N'th project/ ...
I need to minify and move every project inside src/ to dist/ without breaking folder structure. Should look like this:
.
├── dist/
│ ├── index.php
│ └── projects/
│ ├── some-project/
│ │ ├── main.css(minified)
│ │ ├── main.js(minified)
│ │ └── index.html
│ └── N'th project/ (also minified) ...
└── src/
├── index.php
└── projects/
├── some-project/
│ ├── main.css
│ ├── main.js
│ └── index.html
└── N'th project/ ...
Thanks for your time.
I solved it with something like this. If any one want to use:
.pipe(gulp.dest(function(file){
let splittedUrl = file.history[0].split("\\");
let projectName = splittedUrl.slice(splittedUrl.indexOf("projects"),-1);
//console.log(projectName.join("/"));
return "dist/" + projectName.join("/");
}));
gulp.task("projectTest", () => {
return gulp.src("./src/projects/**/*.css")
// minify pipe, etc.
.pipe(gulp.dest('dist/projects'))
});
From https://gulpjs.com/docs/en/api/concepts#glob-base:
A glob base - sometimes called glob parent - is the path segment
before any special characters in a glob string. As such, the glob base
of /src/js/**.js is /src/js/. All paths that match the glob are
guaranteed to share the glob base - that path segment can't be
variable.
Vinyl instances generated by src() are constructed with the glob base
set as their base property. When written to the file system with
dest(), the base will be removed from the output path to preserve
directory structures.
That is a little confusing as written. In my code the part before the globstar ** is the base. So ./src/projects/ is the base. And the directory structure under the base is always preserved - but that wouldn't include projects (because that is part of the base and will be removed automatically in gulp.dest).
In the dest pipe, the directory structures (project1, project2, etc.) are still there but would be sent to your dest folder without the base path at the beginning. So you will need to add whatever part of that base path back into your dest folder if you want it.
So gulp.dest('dist/projects') to get the preserved folder structure put back under projects as you want.
So if what I said is true, this alternative should work as well:
gulp.task("projectTest", () => {
// return gulp.src("./src/projects/**/*.css")
return gulp.src("./src/**/*.css")
// .pipe(gulp.dest('dist/projects'))
.pipe(gulp.dest('dist'))
});
Now the directory structure under src is preserved (becasue src is the base). So you get the same result just sending all that to dist.
You can decide which form you prefer, I think the first version is a little clearer. And if there are files under src that you do not want captured by the gulp.src glob.

Gulp+PUG: get all filenames in directory, tranform and inject them in another file

I have a PUG filestructure that looks something like this:
.
├── _modules
| ├── _footer
| | └── footer.pug
| └── _header
| | └── header.pug
| └── includes.pug
├── _layouts
| ├── default.pug
| └── post.pug
└── index.pug
The main idea is that I want to write a watch task for this, that will get all the filenames in _modules subdirectories and write them into includes.pug file so it would look something like this:
include _footer/footer
include _header/header
I've found some gulp packages that could get the filenames and store them in some variables (array), but I don't know, how to transform them to a string and to inject them into another file (well, I can do foreach of array with filenames and then get a string like 'include '+ filename, but the main problem is that I can't find a package that could insert that strings in a file while I'm doing foreach). Any suggestions how can I do this?
I would appreciate any help. Thank you.

Modify path of gulp.dest

My goal is to find the binaries in here, and elevate them to the first subdir in exe dir.
My simplified (in reality it has more junk, more subdirs) folder structure is this:
src
├── exe
│ └── nix
│ └── binary.out
│ └── blah
│ └── mac
│ └── binary.out
│ └── blah
│ └── win
│ └── src
│ └── trigger
│ └── trigger
│ └── trigger
│ └── binary.exe
│ └── Debug
My goal is to copy just the binary files into dist/exe like this:
dist
├── exe
│ └── nix
│ └── binary.out
│ └── mac
│ └── binary.out
│ └── win
│ └── binary.exe
This is the code I use right now:
var path = require('path');
gulp.src(['src/exe/**/*.out', 'src/exe/**/*.exe'])
.pipe(gulp.dest(function(file) {
var os = file.path.match(/(?:win|mac|nix)/)[0];
return 'dist/exe/' + os + '/' + path.basename(file.path);
}));
However this is still copying the structure even after the os name. It's like it appends the **/ stuff after my returned string. Is there any way to make it not do this?
It like appends the **/ stuff after my returned string. Is there anyway to make it not do this
Yep, that's exactly what it does and it's intentional. Anything before the ** is treated as the base path, anything after is the path that is used when writing the file to the destination directory. (See this answer if you want to know more).
Normally you could use the base option in gulp.src() to change this, but this doesn't really work in your case since you would need one base path for nix/mac and another one for win.
On top of all that you're using gulp.dest() wrong. gulp.dest() specifies the destination directory. You're trying to use it to specify a destination file. That's not possible.
The easiest solution for you is to use gulp-rename:
var path = require('path');
var rename = require('gulp-rename');
gulp.src(['src/exe/**/binary.{exe,out}'])
.pipe(rename(function(file) {
file.dirname = file.dirname.split(path.sep)[0];
}))
.pipe(gulp.dest('dist/exe'));