logo
down
shadow

Using dicom Images with OpenCV in Python


Using dicom Images with OpenCV in Python

By : EvilMoon
Date : October 23 2020, 08:10 PM
it fixes the issue I have figured out a way to get the image to show. As Dan mentioned in the comments, the value of the matrix was scaled down and due to the imshow function, the output was too dark for the human eye to differentiate. So, in the end the only thing i needed to do was multiply the entire mat data with 128. The image is showing perfectly now. multiplying the matrix by 255 over exposes the picture and causes certain features to blow. Here is the revised code.
code :
import numpy as np
import cv2
import pydicom as dicom

ds=dicom.dcmread('sample.dcm')
dcm_sample=ds.pixel_array*128
cv2.imshow('sample image dicom',dcm_sample)

cv2.waitkey()


Share : facebook icon twitter icon
How can I convert Dicom directory (series of dicom images) to 3D volume image?

How can I convert Dicom directory (series of dicom images) to 3D volume image?


By : user4523709
Date : March 29 2020, 07:55 AM
help you fix your problem we can use fullfile which returns a string containing the full path to the file. and dir which returns a list of files and folders that match the string name. When name is a folder, dir lists the contents of the folder. Specify name using absolute or relative path names. name can include wildcards (*). and rest of the things are well commented in program.
code :
    clear all;
    close all;
    clc;
    fileFolder = fullfile('series 9');
    files = dir ( fullfile (fileFolder, '*.dcm'));
    fileNames = {files.name};

    %examine file header (metadata , from dicom stack)

    info = dicominfo(fullfile(fileFolder,fileNames{1}));

    %extract size info from metadata
    voxel_size = [info.PixelSpacing;info.SliceThickness];

    %read one file to get size
    I = dicomread(fullfile(fileFolder,fileNames{1}));
    classI = class(I);
    sizeI = size(I);
    numImages = length(fileNames);

    %read slice images populate 3d matrix
    hWaitBar = waitbar(0,'reading dicom files');

    %create array
    mri= zeros(sizeI(1),sizeI(2), numImages , classI );
    for i=length(fileNames):-1:1
        fname = fullfile(fileFolder, fileNames{i});
        mri(:,:,i) = uint16(dicomread(fname));
        waitbar((length(fileNames)-i+1)/length(fileNames))
    end

    delete(hWaitBar);
Combine more than 1 openCV images and show them in CV2.Imshow() in OpenCV Python

Combine more than 1 openCV images and show them in CV2.Imshow() in OpenCV Python


By : Павел Челядинов
Date : March 29 2020, 07:55 AM
should help you out Use im.resize() function of opencv to resize the image and then do the combining task. Always use a reference dimension such as 1000 x 800 (you can change it)
code :
import cv2

import numpy as np

list_of_img_paths = [path2,path3,path4]

im = cv2.imread(path1)

imstack = cv2.resize(im,(1000,800))

for path in list_of_img_paths:
    im = cv2.imread(path)
    im = cv2.resize(im,(1000,800))
    imstack = np.hstack(imstack,im)

cv2.imshow('stack',imstack)
cv2.waitKey(0)
ROI info in DICOM Images using Evil Dicom

ROI info in DICOM Images using Evil Dicom


By : Joe Centrone
Date : March 29 2020, 07:55 AM
Any of those help Use ImageMatrix(string) to create the suitable helper object. From this object, access the pixel data as floats via the Image property.
Next, you can create for example a filled rectangle image (1 inside, 0 outside the rectangle) with the same dimensions and geometry as the pixel data, multiply each pixel in the image data with the corresponding rectangle pixel, and count the number of non-zero pixels in the composite (original image x rectangle) image.
read and open dicom images using python

read and open dicom images using python


By : Piyush Saxena
Date : March 29 2020, 07:55 AM
This might help you If you are working on windows, I suggest you install Anaconda for working with python. It has most of the libraries and packages.
I suggest you start with installing the following libraries:
code :
import numpy as np
import matplotlib.pyplot as plt
import os, glob
import pydicom
import pylab as pl
import sys
import matplotlib.path as mplPath

class IndexTracker(object):
    def __init__(self, ax, X):
        self.ax = ax
        ax.set_title('Scroll to Navigate through the DICOM Image Slices')

        self.X = X
        rows, cols, self.slices = X.shape
        self.ind = self.slices//2

        self.im = ax.imshow(self.X[:, :, self.ind])
        self.update()

    def onscroll(self, event):
        print("%s %s" % (event.button, event.step))
        if event.button == 'up':
            self.ind = (self.ind + 1) % self.slices
        else:
            self.ind = (self.ind - 1) % self.slices
        self.update()

    def update(self):
        self.im.set_data(self.X[:, :, self.ind])
        ax.set_ylabel('Slice Number: %s' % self.ind)
        self.im.axes.figure.canvas.draw()

fig, ax = plt.subplots(1,1)

os.system("tree C:/Users/Dicom_ROI")

plots = []

for f in glob.glob("C:/Users/Dicom_ROI/AXIAL_2/*.dcm"):
    pass
    filename = f.split("/")[-1]
    ds = pydicom.dcmread(filename)
    pix = ds.pixel_array
    pix = pix*1+(-1024)
    plots.append(pix)

y = np.dstack(plots)

tracker = IndexTracker(ax, y)

fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
plt.show()
DICOM or JPEG for detection and classification Using ultrasound images Dicom or JPEG?

DICOM or JPEG for detection and classification Using ultrasound images Dicom or JPEG?


By : Matej Pipalović
Date : March 29 2020, 07:55 AM
this will help DICOM is the format for medical imaging. EXIF Tags in JPEG are a poor replacement and not standardized. DICOM comes with a standardized header structure providing unambigous information about the image - acquisition technique, date, device, ...
However, DICOM has a long and steep learning curve. So my advice would be:
Related Posts Related Posts :
  • Submitting login form with scrapy
  • How do i edit the favicon in the Browsable API in Django REST framework?
  • multiprocessing.Pool.map_async doesn't seem to... do anything at all?
  • Python Selenium: Stale Element Reference Exception Error
  • Datetime conversion - How to extract the inferred format?
  • Import YAML variables automatically?
  • How to create a powershell shortcut for my python file
  • Python's 'set' operator doesn't work with numpy.nan
  • Pass object fields and one2many fields on same method - Odoo v8
  • Select columns based on column name and location in Pandas
  • Standardizing timeseries in Pandas using interpolation
  • How many tweets can be collected?
  • how format specifier taking value while tuple list is passed
  • How to print a numpy array with data type?
  • Timeout child thread for python3
  • How can I regroup a dataframe and accumulate a colume's values?
  • Bulk Insert into SQL Server with Python not working
  • Removing last rows of each group based on condition in a pandas dataframe
  • Why the css file can not be found in Django template?
  • targeting center of mass - scipy / numpy
  • Foursquare - get tips from VENUE_ID
  • Unpack a dictionary to format
  • encoding special characters in python2
  • Replacing integers with NaN results in the entire column becoming float dtype
  • Python 3.6 - BeautifulSoup4, parse table AttributeError: ResultSet object has no attribute 'findAll'
  • Convert panda date list to python list of date strings
  • escape response from Scrapy to parse json
  • How to create a same dropdown menu for different labels?
  • Why are some python variables uppercase whereas others are lowercase?
  • Machine Learning, What are the common techniques for feature engineering and presenting the model?
  • Modify value of a Django form field during clean() and validate again
  • Heroku Django app can't start up -- 'No module named site'
  • Getting list of dates (excluding weekends)
  • Im trying to create the regular expression to include the text and not the href
  • Python file.readline(2) reads first 2 charectars
  • Groupby with handling empty bin in python
  • Modifying Gcode
  • calling a value in a dictionary within a dictionary (reading a json file)
  • Bouncing ball invalid syntax why is that?
  • Python making a counter
  • Python rstrip and split
  • What does the String mean in numpy.r_?
  • How to correctly extend variable __all__ in a __init__.py?
  • Python behaves weird with piped input
  • Python 3 two dimensional list comprehension
  • How to slice image by broadcasting slices? Error: 'only integer scalar arrays can be converted to a scalar index' in pyt
  • (Python Beginner) Need a start on classes
  • IndexError: At least one sheet must be visible
  • How to solve a system of linear equations over the nonnegative integers?
  • Pandas keep the most complete rows
  • "List index out of range" error in Python Memory Match game
  • Numpy: how to use argmax results to get the actual max?
  • Google Cloud Dataflow can't import 'google.cloud.datastore'
  • Calculate pandas DataFrame column by custom routine which accepts dictionary as input
  • Connect to a Class Method by it's method name holded into a var in a for loop in python
  • PyQt5 signals and threading.Timer
  • Replace 2 characters in a string in python
  • Passing command line arguments from a folder script to a file script
  • Understand the syntaxe X[Y == c] in Numpy
  • Optimize beginner python script about substring replacement
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org