Read, Process, and View Ultrasound Data
This example shows how to import and display a 2-D multiframe ultrasound series, and how to apply a denoising filter to each frame of the series.
You can use the medicalImage
object to import image data and metadata from 2-D medical images and series of images related by time. In this example, you use the properties and the extractFrame
object function of a medicalImage
object to work with a multiframe echocardiogram ultrasound series.
Read Ultrasound Image Series
Specify the name of an echocardiogram ultrasound series contained in a DICOM file.
filename = "heartUltrasoundSequenceVideo.dcm";
Read the metadata and image data from the file by creating a medicalImage
object. The image data is stored in the Pixels
property. Each frame of the image series is a 600-by-800-by-3 pixel RGB image. The FrameTime
property indicates that each frame has a duration of 33.333 milliseconds. The NumFrames
property indicates that the series has a total of 116 image frames.
medImg = medicalImage(filename)
medImg = medicalImage with properties: Pixels: [600×800×116×3 uint8] Colormap: [] SpatialUnits: "unknown" FrameTime: 33.3330 NumFrames: 116 PixelSpacing: [1 1] Modality: 'US' WindowCenter: [] WindowWidth: []
Display Ultrasound Image Frames as Montage
The medicalImage
object stores the image data dimensions in the order spatial-spatial-frames-channel, where spatial indicates the spatial dimensions of each frame, frames indicates the number of frames in the image series, and channel refers to the number of channels in each frame. To be compatible with the montage
function, use the permute
function to reorder the dimensions to spatial-spatial-channel-frames.
pixels = permute(medImg.Pixels,[1 2 4 3]);
Display the image frames side-by-side as a montage.
montage(pixels)
Display Ultrasound Series as Video
The FrameTime
property specifies the number of milliseconds between frames. Calculate the frame rate, in frames per second.
fps = 1/(medImg.FrameTime/1000)
fps = 30.0003
View the ultrasound series as a video by using the Video Viewer app. Specify the frame rate at which to view the video by using the frame rate calculated from the file metadata.
implay(pixels,fps)
Reduce Speckle Noise
Reduce the noise in the ultrasound image series by applying a speckle-reducing anisotropic diffusion filter to each frame. Extract each frame from the medicalImage
object by using the extractFrame
object function, and convert the frame from RGB to grayscale. Apply the filter by using the specklefilt
function. Specify the DegreeOfSmoothing
and NumIterations
name-value arguments to control the smoothing parameters.
[h,w,c,d] = size(pixels); pixelsSmoothed = zeros(h,w,d); for i = 1:d Ii = extractFrame(medImg,i); Ii = im2double(im2gray(Ii)); pixelsSmoothed(:,:,i) = specklefilt(Ii,DegreeOfSmoothing=0.6,NumIterations=50); end
Display the smoothed image data as a video.
implay(pixelsSmoothed,fps)
Store Smoothed Data as Medical Image Object
Create a new medicalImage
object that contains the smoothed image pixels. Use the property values from the original file to maintain the correct frame information.
medImgSmoothed = medImg; medImgSmoothed.Pixels = pixelsSmoothed; medImgSmoothed
medImgSmoothed = medicalImage with properties: Pixels: [600×800×116 double] Colormap: [] SpatialUnits: "unknown" FrameTime: 33.3330 NumFrames: 116 PixelSpacing: [1 1] Modality: 'US' WindowCenter: [] WindowWidth: []
Display the first frame of the new medical image object to verify it contains the smoothed data.
imshow(medImgSmoothed.Pixels(:,:,1))
See Also
medicalImage
| extractFrame
| specklefilt
| montage
| Video Viewer