I have a stl model which consists of a cube that was heated. I wrote a software which calculates the temperature distribution at every voxel in the cube, so it is essentially like a heat map where blue colored voxel is colder region and red colored voxel is warmer region on the cube.
The user provides how many voxels the cube stl model will be divided into and the code calculates the temperature at each voxel in the cube. This information is provided to me in an hd5f file which I can turn into a numpy array with 3 dimensions that indicates the temp at each x,y,z voxel. I want to display this 3d heatmap in the browser using Three Js so the user can rotate and section through the distribution to see how the temperature is distributed in the cube.
So I am trying to figure out how to display this hd5f file or convert the numpy array into something that can be displayed in the browser so that the user can see the temperature distribution on the cube. I found an example where they display a nrrd file in Three Js here. I thought maybe I could convert the numpy array I had into an nrrd file and also display it in the browser like the example using the following code:
import nrrd
import os
nrrd_file_name = os.path.dirname(__file__) +'\\test.nrrd'
nrrd.write(nrrd_file_name, temp_distribution_array, index_order='C') # array is size (61,61,61)
However, when I use the example code and replace their nrrd file with mine, I simply get a black screen with the console stating WebGL: INVALID_OPERATION: texSubImage3D: type FLOAT but ArrayBufferView not Float32Array. So I am unsure how to convert my 3d numpy array or my hd5f file into something that can be visualized in three js.
Hence, I was wondering if there is a better way to approach this or if anyone knows how to display hd5f files into the canvas or is there some other format I could use to display a 3d temperature heatmap in three js?
Related
I am trying to render an stl and save it as a png so it is a preview of the stl.
I have a project that needs to take layer images(png) and save it as 3d(stl). I converted every layer image(approximately 300-400 image) to a numpy array. Then from those numpy arrays I made vertices and faces. My stl files are faces(triangles) aligned on top of each other. So there is no actual body in the final image just faces aligned together.(Layers have no z value)
Here is a single layer from one of my models:
And here is the final model:
And now I am trying to generate an image like the 2nd picture above. So there will be a preview of the stl model. And I am trying to figure a way out to save the preview as a png file. But I couldn't figure out the plot libraries' camera movements.
I tried matplotlib but i suppose there is no camera adjustment setting so it generates a png on a side that I do not want. That's why I want a way to control the camera. There is blender's Python API but it seems pretty confusing.
Any ideas on how to do that in Python?
I have this numpy array of slices of segments of the liver CT(ground truths). I want to export them into a viewable format in tools like blender. The slices are white and black, 0-255. Anything other than liver is black, I want the liver to be viewed in 3d.
The slices are in top view. I used this code in kaggle to view them but just in jupyter https://www.kaggle.com/akh64bit/full-preprocessing-tutorial/data. It can be any way to visualize them.
You may try transform your arrays to DICOM format as mentioned before in stackoverflow: Create pydicom file from numpy array
Than you can easily visualize DICOM images in various platforms!
For new folks stumbling upon this question that are looking to convert pixels / voxels to an STL file or files, this Python workflow has worked for me:
Load stack of images as a 3D NumPy array using imageio.imread().
Segment the foreground from the background using one of the many segmentation algorithms from the scikit-image submodule skimage.segmentation, creating a 3D binary image.
Use the marching cubes algorithm from the scikit-image submodule skimage.measure to convert the voxels of interest to a list of faces defined by vertices on the surface of the volume.
Use numpy-stl to create an stl.Mesh object from the list of faces and vertices (as done in this example) then save the mesh with stl.Mesh.save().
As a bonus, you can use the Python package for the Open3D library to open & view multiple STL files!
I have a series of images of a structure with different z values (each photo is taken 5µm higher than the last one).
I wrote a programm that calculates the area of the structure for each photo. I also have a list that stores this area for each photo as a binary image (background = black, area = white).
Since I basically have all 3 coordinates for my structure I think it should be possible to create a STL file to plot this structre in 3D space.
Since I never did anything in terms of 3D programming I don't really know how to do this.
I would appreciate any help
I have a hyperspectral raster image of an agricultural field with 270 spectral bands. I created a polygon shapefile that delineates which pixels belong to each treatment. There are 250 individual polygons that each correspond to a replication of each treatment. I want to find the average pixel value for each band for all of the pixels that fall within each polygon.
Image of raw hyperspectral data
Image of polygons delineating treatments
I tried using the zonal statistics tool in both ArcGIS and QGIS but both tools can only run statistics on one band at a time. Doing this 270 times seems a little excessive.
I also tried to use the split raster tool in ArcGIS to divide the raster into 250 individual rasters corresponding to each polygon. Once I split the raster, I tried using the band collection statistics tool but found that I could not input all rasters simultaneously although the tool appears to be capable of doing so. Each attempt results in the following error: ERROR 000964 Specified extent is invalid.
I've been conducting my analyses in ArcGIS Pro, QGIS (v.3.4.11), and Python (v.3.7) primarily using GDAL. So, I am open to using any of these options to conduct further analysis. I think this might be doable in Python, but my coding skills aren't great and I'm not sure where to start.
You can use Spectral Python package to read your hyperspectral image.
Lets say,
from spectral import*
img=open_image('<file location>') #read into img
make a numpy mask image from the polygon shapefile you created, probably according to the classes(color coding).From this image, you can extract the pixel co-ordinates.
import numpy as np
from matplotlib.image import imread
mask_img=imread('<polygon mask image location>')
lets say for one polygon you have assigned class 1,so for all the pixel points in class1 polygon
x,y=np.where(mask_img==1) #get the required co-ordinates
use the same on the hyperspectral image
band_avg=[]
for band in np.arange(270):
sum,avg=0.0,0.0
for i in np.arange(len(x)): #no. of pixels in polygon class1
sum+= img[x[i],y[i]]
avg=sum/len(x)
band_avg.append(avg)
print(band_avg)
band_avg will return average pixel value for each band for all of the pixels in a particular class/polygon color. You can repeat the above for other classes/polygons by getting x,y for different class ID's.
I have triangulated geometry (STL file) and I have the values of a vector field for each triangle. I want to plot the triangles with the vector field on each triangle and also color the triangle according to the magnitude of the vector.
Is there any way of accomplishing this using languages like python or any open-source software such as gnuplot,etc.?
If not, what about software like MATLAB?
According to http://en.wikipedia.org/wiki/STL_%28file_format%29 you can store color and normal informations in a STL binary file. I'd make a python script that creates a new binary STL where each facet (triangle) has a color and use the normal to store the vector. Then I'd import this file in Blender and ask it to display the normals and the flat face colors. You'll then do an OpenGL render (it is just a button to push) to export a PNG file of the view you want to see.
Do you have a sample scene ?