当前位置:网站首页>Simpleitk use - 3 Common operations
Simpleitk use - 3 Common operations
2022-07-02 22:33:00 【Ton ton don't fight wild】
List of articles
1. corrosion / inflation
1.1 python Realization
import SimpleITK as sitk
demo_mask_path = "./seg.nii.gz"
demo_mask_image = sitk.ReadImage(demo_mask_path)
dilate_img=sitk.GrayscaleDilate(demo_mask_image , kernelRadius=[3,3,3])
sitk.WriteImage(dilate_img, "./dilatenii.gz")
The effect is similar to the following :
Reference resources :
- Welcome to the SimpleITK Image Filtering Tutorial
- Find it according to the previous reference link :
GrayscaleErodeImageFilter
, Go on SimpleITK Online documentation for To search - And find out :itk::simple::GrayscaleErodeImageFilter Class Reference
- These include :GrayscaleErode() This interface .
- If you accidentally forget the meaning of corrosion and expansion , Take a look at this article :opencv Learning notes ( 8、 ... and ): Image morphology operation
- Corrosion is the dark side getting more , Less light , Every time filter Take the minimum value to cover (0-255,0 It's black )
- Expansion is the reduction of darkness , Less light , Every time filter Take the maximum value to cover
- SimpleITK Analyze medical images
- ITK07 Mask processing
- ITK Do corrosive operation , This uses
itkGrayscaleErodeImageFilter
This class
1.2. C++ Realization
If you want to search ITK Some classes of , You can go straight to SimpleITK Documents Search in , Those... Will be shown here ImageFilter Corresponding ITK
The documentation in .
for example : Search in the document erosion
, You can get the following results , It's better to see which function you need
There are several more. , I won't put the screenshot here
1.2.1 inflation (Dilate)
Expansion corresponds to ImageFilter yes :
- itk::BinaryDilateImageFilter< TInputImage, TOutputImage, TKernel > Class Template Reference
- Expansive C++ Examples in :SphinxExamples/src/Filtering/BinaryMathematicalMorphology/DilateABinaryImage/Code.cxx
- As follows :
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkFlatStructuringElement.h"
#include "itkBinaryDilateImageFilter.h"
int main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " <inputImage> <outputImage> <radius>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputImage = argv[1];
const char * outputImage = argv[2];
const unsigned int radiusValue = std::stoi(argv[3]);
using PixelType = unsigned char;
constexpr unsigned int Dimension = 2;
using ImageType = itk::Image<PixelType, Dimension>;
const auto input = itk::ReadImage<ImageType>(inputImage);
using StructuringElementType = itk::FlatStructuringElement<Dimension>;
StructuringElementType::RadiusType radius;
radius.Fill(radiusValue);
StructuringElementType structuringElement = StructuringElementType::Ball(radius);
// Mainly this sentence
using BinaryDilateImageFilterType = itk::BinaryDilateImageFilter<ImageType, ImageType, StructuringElementType>;
BinaryDilateImageFilterType::Pointer dilateFilter = BinaryDilateImageFilterType::New();
dilateFilter->SetInput(input);
dilateFilter->SetKernel(structuringElement);
dilateFilter->SetForegroundValue(255); // Value to dilate
try
{
itk::WriteImage(dilateFilter->GetOutput(), outputImage);
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
1.2.2 corrosion (Erode)
Corrosion corresponds to ImageFilter yes :
- [itk::BinaryErodeImageFilter< TInputImage, TOutputImage, TKernel > Class Template Reference](itk::BinaryErodeImageFilter< TInputImage, TOutputImage, TKernel > Class Template Reference)
- Corrosive C++ Examples in :SphinxExamples/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/Code.cxx, as well as SphinxExamples/src/Filtering/BinaryMathematicalMorphology/ErodeABinaryImage/Code.cxx
2. SimpleITK Conduct padding operation
My usage scenarios :
- Yes mask The image is done crop, Deleted mask Some unnecessary marking points in
- crop after mask The image size has changed , So we need to change back to crop Previous size
import SimpleITK as sitk
demo_mask_path = "./seg.nii.gz"
demo_mask_image = sitk.ReadImage(demo_mask_path)
cropped_image = sitk.Crop(demo_mask_image ,lowerBoundaryCropSize=[0,0,0],upperBoundaryCropSize=[crop_size,0,0])
half_image_y_pad =sitk.ConstantPad(cropped_image ,padLowerBound=[0,0,0],padUpperBound=[crop_size,0,0],constant=0)
ConstantPad
and Crop
It's like , Just one is cutting , One is to add .
Reference resources :
3. SimpleITK Extract a slice
According to the reference 1, You can know ,
- Pure use SimpleITK Of Image Go slice , The code is more complex
- It is suggested to directly turn to numpy Array
import SimpleITK as sitk
demo_mask_path = "./seg.nii.gz"
demo_mask_image = sitk.ReadImage(demo_mask_path)
demo_array = sitk.GetArrayFromImage(demo_mask_image)
# Do some array slicing
....
demo_image =sitk.GetImageFromArray(demo_array)
demo_image.CopyInformation(demo_mask_image )
Reference resources :
- SimpleITK file :Advanced Image Reading
- SimpleITK reading a slice of an image
- Python/ExtractSlice.py
- itk::simple::ExtractImageFilter Class Reference
4. SimpleITK Of GetSize and GetArrayFromImage After xyz Corresponding
Reference resources :【SimpleITK course 】GetSize() Methods and GetArrayFromImage() Method
namely
padding_path="XXXX.nii.gz"
padding_image=sitk.ReadImage(padding_path)
print(padding_image.GetSize())
padding_array = sitk.GetArrayFromImage(padding_image)
print(padding_array.shape)
padding_array[78,131,80]
> (240, 240, 155) (x,y,z)
(155, 240, 240) (z,y,x)
2
5. SimpleITK Threshold osteotomy
The data I use is relatively simple , Here is a simple preprocessing .
import SimpleITK as sitk
image_path = "./im.nii.gz"
image = sitk.ReadImage(image_path)
skull_mask =sitk.BinaryThreshold(image, lowerThreshold=125, upperThreshold=2000, insideValue=1, outsideValue=0)
# stay 125~2000 Within the scope of , The assignment is 1, Out of range , The assignment is 0. Got mask Namely 125~2000 The content of this intensity value , Bones .
Like the image below :
- Above is the brain CT Adjust the window width and window level to level:700,window:500 The resulting image
- Here are the results of using threshold osteotomy , It looks ok
Reference resources :
边栏推荐
- ServiceMesh主要解决的三大痛點
- "New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
- 基于ASP.net的手机销售管理系统(二手手机销售管理系统)+ASP.NET+C#语言+VS2010+数据库可以用于课设、毕设学习
- Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
- How do I access the kubernetes API?
- Les trois principaux points de douleur traités par servicemesh
- [shutter] shutter resource file use (import resource pictures | use image resources)
- : last child does not take effect
- Web side defense Guide
- Market Research - current market situation and future development trend of handheld wound imaging equipment
猜你喜欢
A specially designed loss is used to deal with data sets with unbalanced categories
From personal heroes to versatile developers, the era of programmer 3.0 is coming
20220702 how do programmers build knowledge systems?
[shutter] shutter application life cycle (foreground state resumed | background state paused | inactive | component separation state detached)
Promise optimized callback hell
Scrcpy this software solves the problem of sharing mobile screen with colleagues | community essay solicitation
From "bronze" to "King", there are three secrets of enterprise digitalization
Official announcement! The golden decade of new programmers and developers was officially released
Phpcms realizes the direct Alipay payment function of orders
The failure rate is as high as 80%. What should we do about digital transformation?
随机推荐
Gee: (II) resampling the image
100 important knowledge points that SQL must master: using cursors
Market Research - current market situation and future development trend of aircraft wireless intercom system
Market Research - current market situation and future development trend of genome editing mutation detection kit
[shutter] shutter page life cycle (initialization period | createstate | initstate | update period | build | destroy period | dispose)
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
[001] [arm-cortex-m3/4] internal register
[QT] QT multithreading development - four methods to realize multithreading design
Infrastructure is code: a change is coming
使用 EMQX Cloud 实现物联网设备一机一密验证
Pointer array parameter passing, pointer parameter passing
[C question set] of V
Secondary development of ANSYS APDL: post processing uses command flow to analyze the result file
Market Research - current market situation and future development trend of total nutrition products
sql service 截取字符串
New feature of go1.18: introduce new netip Network Library
TinyMCE visual editor adds Baidu map plug-in
Attack and defense world PWN question: Echo
"New programmer 003" was officially launched, and the cloud native and digital practical experience of 30+ companies such as Huawei and Alibaba
记录一下微信、QQ、微博分享web网页功能