multiple images in one figure using a scrollbar

8 Ansichten (letzte 30 Tage)
Prashant Verma
Prashant Verma am 3 Nov. 2020
Beantwortet: Deepak am 15 Okt. 2024
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

Antworten (1)

Deepak
Deepak am 15 Okt. 2024
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.

Kategorien

Mehr zu Modify Image Colors finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by