# Cone-Beam Geometry X-ray Simulator for STL Files in MATLAB
This package performs simulated, 2 dimensional (2D) x-ray projections on 3 dimensional objects (3D), described in stereolithography format (STL) utilizing MATLAB. Cone-beam geometry was chosen as the x-ray model due to the utility advantages it has over parallel and fan beam x-ray geometry (simplest real world scenario, does not require collimater in order to parallelize beams, less equipment etc.).
## 1. Getting Started
Add the folder X-ray Simulation to your MATLAB path. Inside the folder you will find the main function, XraySim.m, along with several other functions that are necessary to run the simulations. References for used packages are at the end of this document.
Make sure the STL file you are planning on simulation x-ray projections from is in the same folder as the main function XraySim.m, along with the functions: READ_stl.m, VOXELISE.m, and projection2D.m.
### Prerequisites
Make sure the STL file you are planning on simulation x-ray projections from is in the same folder as the main function XraySim.m, along with the functions: READ_stl.m, VOXELISE.m, and projection2D.m.
### Simulation Overview
This 2D x-ray projection process from this package can be summarized by the following steps:
1. Place the STL file containing the 3D mesh object that you want to obtain simulated x-rays from into the “X-ray Simulation” folder.
2. Use the matlab command, Help XraySim to determine the desired function inputs for the wrapper function XraySim.m. The simplest functionality requires just the STLFILE.stl as input.
3. Run the XraySim.m function.
4. XraySim.m then uses the functions READ_stl.m and VOXELISE.m to read in the 3D mesh data of the object, and uses three dimensional raycasting to voxelize it.
5. XraySim.m sets various simulation parameters based on the input at step 3.
6. The 3D object array is then fed into the projection2D.m function, which computes the slice by slice 2D Conical X-ray projection in the Z-direction.
7. Lastly, the projection is then saved as a Bitmap file and saved to the current folder.
## 2. Package Functions
This section gives a brief overview of the package functions and their functionality. Use the MATLAB help command to receive a more in depth description on the input parameter options, if needed.
### XraySim.m
This is the wrapper function for the package and at minimum requires one input, the STL file. Other optional input options include the grid size for the voxelization (integer or 1xN array), a string input (to name the output BMP file), and several input argument pairs. This wrapper function calls READ_stl.m to read in the 3D STL file, and uses VOXELISE.m in order to turn the mesh into a 3D image array (voxelization). After various imaging simulation parameters are set, it then feeds the 3D image array into projection2D.m which ouputs a 2D x-ray image that is the cone beam projection of the 3D STL mesh object in the Z-direction. Finally it saves that image to the current directory the code is operating from.
### READ_stl.m
This function and VOXELISE.m are taken from the voxelisation toolbox by Adam A1. This function specifically reads the mesh data from an STL file into MATLAB that can be both binary and ascii formats. It uses textscan to read ascii files all at once, rather than one line at a time, which makes the overall speed considerably faster. Lastly, it uses fread for binary files also making its computation speed fast. An example of STL ASCII file structure is below:
```
Solid object name
Facet normal x y z
Outer loop
Vertex x y z
Vertex x y z
Vertex x y z
End Loop
End facet
(Repeat for all facets in file)
```
### VOXELISE.m
This function utilizes READ_stl.m. to read in the 3D triangular-polygon mesh data into MATLAB in order to voxelize it into a 3D image array. This code utilizes a ray intersection method similar to the method described by Patil S., and Ravi B.2.
There are multiple options for raycasting directions, but for reliability and accuracy we run it in all three cartesian directions, XYZ. To summarize, pixel by pixel rays are computed in all three Cartesian directions directions and wherever a ray hits the surface of a mesh, that coordinate is given a 1. This process continues for all rays, creating a 3D binary mask representing the surface object. The inside is then “filled” with 1’s finishing the process off and leaving a 3D logical array representing the object’s shape.
### Projection2D.m
This code is adapted from projection.m, which takes a 3D image array (not logical) and computes the 2D cone x-ray projections in the Z-direction. The output of VOXELISE.m is a logical array so the 3D array must converted into either a single/double or grayscale image. These projections are computed using geometric re-sampling meshes, and 2-dimensional interpolation in order to determine the projection of each Z-slice onto the detector. The mathematics are explained later in the section 4.
The original projection.m function applies the projection in the Y-direction compared to my adaptation which projects in the Z-direction. This was done in order to maintain the correct geometry in the simulation. Future versions can include adding object rotations in order to examine different angled projections, but for the sake of code readability and efficiency it was not added.
## 3. Assumptions
There are multiple assumptions are made for this implementation to function smoothly. These range from experiment parameters, to the cartesian geometry in the setup. The main assumptions are described below.
### STL File
STL files can be in either the ascii or binary file formats. The main assumption with the STL mesh is that triangular facets are utilized instead of any 2D shape. The voxelization code specifically is written with this assumption in mind. Additionally, the mesh that is ray-traced must be properly closed (“watertight”), to avoid artifacts during voxelization.
### Simulation Setup
This implementation assumes the object is being imaged from x-rays in the z-direction. The setup has the center (x,y,z = 0,0,z) of the source, object, and detector plate all aligned along the Z-axis. The centre of the object is considered the origin (0,0,0). The x-rays can be visualized as if they are coming from a source above the object, projecting x-rays upon a 2D X-Y detector array beneath it. Visualizing further, the x-rays could be taken during total hip replacement surgery, where the hip joint lies over the x-y detector. *Figure 1* at the end of the ReadMe gives a representation of the setup.
### Parameters
There a multitude of parameters that are used in the simulation process (specifically projection2D.m) that are assumed and set automatically to make computation easier. It should be noted that the option to set them any of them manually will be available in future versions for testing:
#### Gridsize
The x,y,z grid voxelization of the 3D STL file object is assumed to have enough voxels to fully represent the 3D model properly. It is recommended to have at least 100x100x100 voxelization (to be sure). It is recommended to use equal dimensions but it is not necessary.
Raycasting Direction: VOXELISATION.m is set to use raycasting in all three cartesian directions in order to provide the most accurate voxelization of the 3D mesh.
#### Object real size
The real size parameters for the 3D array encompassing the object is assumed to have a 1 to 1 size correlation with the grid parameters (1 pixel = 1 mm).
#### Detector panel pixel density and real size
To simulate a real detector, 256x256 pixels was selected as the pixel resolution, and calculated the approximate real size dimensions of the detector in order to achieve 300 PPI2, as 375x375 mm:.
#### Distance of X-ray source to Detector
The distance of the x-ray source to the detector was kept constant at 1000 mm for this implementation, in order to simplify object dist
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计&课设-MATLAB中的X射线仿真方案.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共30个文件
m:8个
bmp:6个
png:4个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
2 下载量 119 浏览量
2024-01-08
22:36:55
上传
评论
收藏 2.78MB ZIP 举报
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![mp4](https://img-home.csdnimg.cn/images/20210720083504.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PDF.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PDF.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/BMP.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/DOCX.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/DOCX.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PDF.png)
共 30 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/1ad39e95093044228d03f0d7ce161a82_zy_dreamer.jpg!1)
![avatar-vip](https://csdnimg.cn/release/downloadcmsfe/public/img/user-vip.1c89f3c5.png)
白话机器学习
- 粉丝: 9798
- 资源: 7681
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 简单小游戏制作-飞行棋
- Python数学建模例子.rar
- Java项目-基于SSM+JSP的校园外卖配送系统的设计与实现(源码+万字LW+部署视频+代码讲解视频+全套软件)
- Color-Transformer introduction
- FastStone Capture屏幕长截图软件包
- Table IoT物联网工具,简单快速的搭建物联网服务平台
- zheng2020 ecg new dataset-12 lead-add-label
- """YOLOv5-specific modules Usage: $ python path/to/models/y
- onnx-while-test.cpython-37
- 基于MapReduce的招聘数据清洗项目(免费提供源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)