i am trying to simulate a CFD analysis of a basic profile in python (see image), this is generated using 3 X and Y arrays. Are there any llibraries which can achive this for pyhton?
I have tried looking into Pyfoam however it looks rather complicated and i was hoping for something which can be initiated from a python file rather than the console.
Related
I see nearly similar posts, though not quite and I can't seem to adapt any of them to Python. This post suggests an R solution using method="SANN" in optim(): though I can't seem to duplicate it in Python. I want to create a model/plot using (n,min,max,mean,sd,25%,50%,75%,skew, and kurtosis) as 10 known parameters WITHOUT using a distribution family. I can do it fine with a dist family, for example:
x = np.linspace(39,401,100)
plt.plot(x, scipystats.???.pdf(x,p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9])
Then use the model for simulation using a random generator. For example:
ModDist = ???.rvs(p0=n,p1=min,p2=max,p3=m,p4=sd,p5=25,p6=50,p7=75,p8=s,p9=k,rs=3)
It does not have to be only scipy if pandas, numpy, etc.., or combined can work.
Any ideas please?
Im new to medical image processing. how can i convert 3D DICOM medical images to numerical matrix format using either python or c++?
Another option, if you really want "3D" dicom image support (ie CT/MR/NM/PET 3d series - as opposed to purely 2D image handling) and you want do anything really 3d related and/or more complex, you might want to check out simple ITK.
That gives you very powerful true 3d handling and is fast (it's wrapped around complied C). It includes, for example, full 3D image registration and various filters/tools etc.
It can read an entire series at once and automatically create a fully spatially aware 3D numpy array for you (ie it takes care of processing all the dicom 3D spatial orientation/spacing etc tags for you)
However, because it's a lot more powerful than pydicom, it also has a much steeper learning curve - but does have many examples and online jupyter notebook tutorials.
...so, depending on your needs it might be good for you. However, if you only really want basic 2d image-at-a-time type processing, pydicom is the way to go.
You can use pydicom package in python. You can install it in python by:
pip install pydicom
Here is a simple example of reading DICOM images and converting to numpy array:
import os
import pydicom
import numpy as np
dicom_dir = your_dicom_folder_of_slices
file_names = os.listdir(dicom_dir)
file_names.sort()
dicom_data = []
for name in file_names:
path = os.path.join(dicom_dir, name)
dicom_data.append(pydicom.read_file(path))
array = [data.pixel_array for data in dicom_data]
array = np.stack(array, axis=-1) # or 0 if 'channel_first'
Here is a detailed example.
I prefer using SimpleElastix for medical image processing. it has many methods for segmentations and many other helpful methods. it is available in both python and C++. In my experience SimpleElastix handled DICOMS and niftis better than other Packages.
GOAL: I have to create a 3d model of a machine part. I have about 25 images of the same thing taken from different angles.
Progress: I am able to extract the coordinates for a label that is on the machine for most of the images.
Problem: but I have no idea how to proceed. I have read a bit about aero-triangulation, but I couldn't figure out how to implement it. I would really appreciate it, if you could guide me in the right direction.
It would be really helpful, if you could provide your solutions using python and opencv.
Edit: sorry but I cannot upload the code for this one as it is confidential. don't blame me please I am just an intern. Although I can tell that I cropped a template of the label from an image and then used Sift to match that template on all the images to get the coordinates of the label.
If you want to implement things yourself with OpenCV, I would command looking at SIFT (or SURF) features, RANSAC and the epipolar constraint. I believe the OpenCV cookbook describe those. Warning: math involved. And I don't know how to do dense mapping in OpenCV.
I know the GUI program "VisualSFM" that can automatically recreate 3D model from images. It uses SFM and other command line utilities behind the scenes. Since everything is opensource, you could create a python wrapper around the actual libraries (I found https://github.com/mapillary/OpenSfM asking Google). VisualSFM prints the command it calls, so a hacky way could be to call the same commands from python.
If it is a simple shape and you don't want to automate it, it could be faster to model it yourself (and the result could look better). In 1.5 week I managed to learn the basics of blender and to model a guitar necklace: https://youtu.be/BCGKsh51TNA . And I would now be able to do it in less than 1h. How long are you ready to invest to find a solution with OpenCV?
I'm VERY new to Python (been working in it for only a day and with no previous programming experience), and for a project I'm looking to make a histogram within a dedicated window in an existing GUI. At this point I'm just looking for it to contain randomly generated data. I'm using pyqtgraph, numpy, and Python 3.
I've been trying to rework this code which i got to work and creates a scatter plot with random data and places it within my GUI window:
def upd_lowerplot1(self):
""" Function to update bottom plot 1. """
# Clear Plot
self.ui.ui_botplot1.clear()
# Now generate the plot
x = np.random.normal(size=1000)
y = np.random.normal(size=1000)
self.ui.ui_botplot1.plot(x, y, pen=None, symbol='o')
I haven't found any examples on here or elsewhere that make much sense to me. If anyone could walk me through how to alter this code in baby steps that would be fantastic, trying to learn, not just get an answer with no understanding.
I'm looking for some tool/library that is able to draw simple 2d geometries from text file or programatically. I already found List of interactive geometry software but that not quite what I'm looking for. I would prefer something more similar in usage to graphviz or gnuplot. I already wrote some scripts for gnuplot but this tool has been designed for different purposes. Required functionality:
support for different kind of 2D geometries: points, segments, lines, circles, polygons
simple input type format maybe similar to postgis Well Known Text
support for objects additional data like tags and colors definition
output in common image format or some kind of interactive GUI (with zoom in/out and select object)
configurable grid
autoscale or draw in defined area
I will use it for testing geometry algorithms and don't want to reinvent the wheel.
Matplotlib. I'm not familiar with all the aspects of this Python library but I've heard it is pretty good.
To quote their introduction,
matplotlib is a python 2D plotting
library which produces publication
quality figures in a variety of
hardcopy formats and interactive
environments across platforms.
matplotlib can be used in python
scripts, the python and ipython shell
(ala MATLAB®* or Mathematica®†), web
application servers, and six graphical
user interface toolkits.
matplotlib tries to make easy things
easy and hard things possible. You can
generate plots, histograms, power
spectra, bar charts, errorcharts,
scatterplots, etc, with just a few
lines of code. For a sampling, see the
screenshots, thumbnail gallery, and
examples directory
(source: sourceforge.net)
>
For example, using "ipython -pylab" to
provide an interactive environment, to
generate 10,000 gaussian random
numbers and plot a histogram with 100
bins, you simply need to type
x = randn(10000)
hist(x, 100)
For the power user, you have full
control of line styles, font
properties, axes properties, etc, via
an object oriented interface or via a
set of functions familiar to MATLAB
users. The pylab mode provides all of
the pyplot plotting functions listed
below, as well as non-plotting
functions from numpy and
matplotlib.mlab.
Maybe dia, with it's SVG output option is what you're looking for? It can be scripted in Python.