multiple images in one figure using a scrollbar

조회 수: 5 (최근 30일)
Prashant Verma
Prashant Verma 2020년 11월 3일
답변: Deepak 2024년 10월 15일
I have a number of 2D dicom images (some monochrome, some RGB, also different sizes) that I want to display in one Figure, with the ability to scroll from one image to another in the Figure. How can I do this?
Thanks
PV

답변 (1개)

Deepak
Deepak 2024년 10월 15일
Hi Prashant,
As I understand it, you have several “dicom” figures that are either monochrome or RGB and are of different sizes. You want to display them in a single figure in MATLAB, with the ability to scroll from one image to another in the figure.
To achieve this, we will first load all the images in MATLAB and read them using thedicomread” function. Next, we need to create a figure and display all the images using theimshow” function. We can then create a slider by using theuicontrol” function and add a custom listener to it to update the image while scrolling.
Here is the complete MATLAB code that accomplish this task:
% Load DICOM images
fileNames = {'image1.dcm', 'image2.dcm', 'image3.dcm'};
numImages = length(fileNames);
images = cell(1, numImages);
for i = 1:numImages
images{i} = dicomread(fileNames{i});
end
% Create the figure and UI controls
hFig = figure('Name', 'DICOM Image Viewer', 'NumberTitle', 'off');
hAx = axes('Parent', hFig);
hImg = imshow(images{1}, 'Parent', hAx);
% Add a slider
hSlider = uicontrol('Style', 'slider', 'Min', 1, 'Max', numImages, ...
'Value', 1, 'SliderStep', [1/(numImages-1) , 10/(numImages-1)], ...
'Position', [100, 20, 300, 20]);
% Add a listener to the slider
addlistener(hSlider, 'ContinuousValueChange', @(src, event) updateImage(hImg, images, round(get(src, 'Value'))));
% Callback function to update the image
function updateImage(hImg, images, index)
imshow(images{index}, 'Parent', get(hImg, 'Parent'));
end
Attaching the documentation of functions used for reference:
I trust this information proved helpful.

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by