CSE(IOT) SIES GST Data Science for Health and Social Care lab
Prathamesh Gawali Experiment No.-4 222AX066
Aim: Bio Medical Image Analytics
Theory: The actual content of the image depends on the instrument used: photographs measure
visible light, x-ray and CT measure radiation absorbance, and MRI scanners measure magnetic
fields. This program work with sections of a computed tomography (CT) scan from The Cancer
Imaging Archive. CT uses a rotating X-ray tube to create a 3D image of the target area.
Imageio: is a versatile package. It can read in a variety of image data, including JPEG, PNG, and
TIFF. But it's especially useful for its ability to handle DICOM files.
Metadata
ImageIO reads in data as Image objects. These are standard NumPy arrays with a dictionary of
metadata.
Metadata can be quite rich in medical images and can include:
• Patient demographics: name, age, sex, clinical information
• Acquisition information: image shape, sampling rates, data type, modality (such as X
Ray, CT or MRI)
Plot images:Matplotlib's imshow() function gives you a simple way to do this. Knowing a few
simple arguments will help:
cmaR controls the color mappings for each value. The "gray" colormap is common, but many
others are available.
vmin and vmax control the color contrast between values. Changing these can reduce the
influence of extreme values.
plt.axis('off ) removes axis and tick labels from the image.
Load volumes
ImageIO's volread() function can load multi-dimensional datasets and create 3D volumes from a
folder of images. It can also aggregate metadata across these multiple images.
For this exercise, read in an entire volume of brain data from the "./dataset/tcia-chest-ct-sample"
folder, which contains 5 DICOM images.
Field of view
The amount of physical space covered by an image is its field of view, which is calculated from
two properties:
CSE(IOT) SIES GST Data Science for Health and Social Care lab
• Array shape, the number of data elements on each axis. Can be accessed with
the shape attribute.
• Sampling resolution , the amount of physical space covered by each pixel. Sometimes
available in metadata (e.g., meta['sampling']).
Advanced plotting
• To plot N-dimensional data, slice it!
• Non-standard views
• Axial (Plain)
• Coronal (Row)
• sagittal (Col)
Generate subplots
You can draw multiple images in one figure to explore data quickly. Use plt.subplots() to generate
an array of subplots.
fig, axes = plt.subplots(nrows =2, ncols=2)
Slice 3D images: The simplest way to plot 3D and 4D images by slicing them into many 2D
frames. Plotting many slices sequentially can create a "fly-through" effect that helps you
understand the image as a whole.
Code & Output:
In [ ] : iJport nurn py as np
iJport sdpy
iJport im ageio
iJport mat plotlib .py plot as
plt f rom p p rint import ppr in t
plt.rcPararns['figure.figsize '] (10,, 8)
In [ ]: # load "chest-220 . d cm"
im = irnageio.imread (' ./dataset/tcia -chest-ct- sarnple/chest- 220.dcrn' )
# Print image attributes
print('Image type:' , type (im)}
print('Shape of image array :', irn .shape)
Image type : <class 'imageio.core.util .A rray
'> Shape of image a rray : (512, 512)
CSE(IOT) SIES GST Data Science for Health and Social Care lab
In [ ] : # Print the: available me:tadata fields
rr:irrt(im . eta)
Diet ( [ ( 'Tra nsf ersy ntaxu m ' , '1., 2,. s..e,. 1.em:m.1.. 2 '),
( 'SOf»C:lass D ' , ' 1.2 .. 840.. 10028 .. 5 .1..4 .1..1.2. ' ),
( 'SOPirnst:anc ID ' ,
·1.. 3.6 .. 1.4 .. 1.14519 .5.. 2 .1.. 5168 .. !l..900 .2.9086680737014<680!l..e46392.918.286 ' ),
( 'st: dyD ate ' , '2004e1529 ') ,
( 'seriesDate ' , '20f)t!0 51.5 ' ) ,
( 'caritent::o a e ' , ' 20240515 ' ),
( 'St: dyT· e ' ·' '115200 ' ),
( 'ser iesTi ' , '1152154 ' ),
( 'caritent:Tim e ' , ' 115325 ') ,
( 'Mod a lity' , 'C ' ) ,
( .Man ufacturer .' ' E ME ICAL SVS.TIBMS..)'
( 'st: dyDes cription ' , ' f>iE T c with r.egist:ered r.; ' ),
( • SeriesDescriptiari .' • CT 1C;.G E:S. - RiESEARCH '
)' ( 'Pat ient: am e' , ' STS_087 ' ) ,
( 'Patient:m ' ' 'STS_e07 ' )'
( 'Pat ient:B:i.rt:hDate' , ' ' ),
( 'Pat ient:s.oex ' , ' ' ),
( 'Pat.ien ' eiht ' , s.2. .,
0), ( 'st: d'yinstanceurn '
,
'1,. 3.6 ., 1.4 ., 1.14519 .5,. 2 .1.,. 5168,. !l..900 .3.SB977377904l44816048<% 607e,90 ' ),
( 'seriesllflstanceum ' ,
'1,. 3.6 ., 1.4 ., 1.1 519 .5,. 2 .1.,. 5168,. !l..900. 311547783684032 5822808 3038439 ' ) '
( 'Seriesr · er ' , 2),
( 'Acq uisition uctier ' ,
1), ( 'Instanc m !J.e r ' ·'
57),
( 'ImaPas:i.ti n Pat:ient:' , ( -250 ,.!0, - 250.0, - 180 ., 62)),
( ' Tim aorient:a t ion Patie:nt ' , (1,. 0, 0.0, 0 .0, 0 .0., 1.0, 0., 0)),
( • s- plesPer Pixoe l ' , 1) ,
( ' ·Cfl'IS ', 5:12 ),
( 'Cal s', 51.2),
( 'Pi:>:Jelspa cin,g ' , (!0 .976562 , 0 . 9761562)),
( 'Bits."'-llocat:e.d ' ,
16.) , ( 'Bitsstared ' ,
:16),
( 'H i,gtlB.it: ', 15) ,
( 'Pi:>:Je iqprese:ntat:icn ' , 0 ) ,
( ' es c aleirn tet'cept: ' , - 1.024 ,.
0) , ( ' escales. ope' , 1.0) ,
( 'Pi:>:Je Data ' ,
' Data converted t n . y a r:rey, ra•. data re ved ta prese NJe mory ' ),
In [ ] : f ig, a x = plt .su bp lot s( l, 3, f igsize= ( 15, 10) )
# OrDlv the image in grayscale
ax[ 0 ] . imsho>t( im, cmap= ' gray ' );
II Dra1v the image l·Jith greater contrast
ax[ l] . imshow( im, cm ap= ' gray ' , vmi n =- 200 , vmax=200 ) ;
II Remove axis ticks and LabeLs
ax[ 2 ] . imsho>i( im , cmap= 'gray ' , vmin = - 200 , vmax=200
) ; ax[2 ]. axis ( 'of f ' ) ;
0 0
100 100
200 200
300
-
300
400
500
400
500
' Y
'",- - - -- ,/
0 100 200 300 400 500 0 100 200 300 400 500
CSE(IOT) SIES GST Data Science for Health and Social Care lab
In [ ] : # Read -in each 2.D i.mage
im1 image.io.. imread ('./dataset/tcia-chest-ct - sam ple/chest-
220.dcrn ' ) im2 imageio.imread ('./dataset/tcia-chest-ct -
sample/chest -221.dcrn ' ) im3 imageio.imread ('./dataset/tcia-
chest-ct-sam ple/chest-222.dcrn ' )
volume
# Stack i.mages into a
vol = np .stack([iml, irn2, im3]
axis=0) print ('Volume dimensions:
· vol .sh ape)
Volume dimension s: (3, 512, 5:II. 2)
In
[
5 11 s ( 20 ,IS 11 s (1
·.
In []: # InitiaLize figure and axes grid
fig, axes = plt .subplots(nrows=l, ncols=2)
# Dra1 an images on each
subplot axes[0].imsho 1(iml,
cmap= ·gray '); axes
[1].imshow(im2, cmap= 'gray
');
# Remove ticks/Labels and render
axes[0].axis('off');
axes [l].axis('off');
CSE(IOT) SIES GST Data Science for Health and Social Care lab
In (J : Plu -- OM u L r
i, axes pl .subplots(l, 5, f 1si e (l5,
IS))
In [ ) : # Select frame fra l "val"
iml = vol[ : , 256, :]
im2 = vol[ : , :, 256 )
# Compute aspect ratias
d0, dl, d2 = vol.meta [ ' sampling ' )
aspl = d0 I d2
asp2 = d0 I d l
t; Plot the images on a subplots array
fig, axes = plt. subplots ( 2 , 1, figsize= ( 15, 8))
axes[0) . imshow( iml, cmap= ' gray ' , aspect= asp l) ;
axes [l) . imshow( im2 , cmap= ' gray ' , aspect= asp2 ) ;
00
25
00
2.5
Conclusion: Biomedical Image Analysis demonstrates the benefits reaped from the
application of digital image processing , computer vision, and pattern analysis techniques to
biomedical images, such as adding objective strength and improving diagnostic confidence
through quantitative anal