multiple images in one figure using a scrollbar
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Deepak
el 15 de Oct. de 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 the “dicomread” function. Next, we need to create a figure and display all the images using the “imshow” function. We can then create a slider by using the “uicontrol” 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.
0 comentarios
Ver también
Categorías
Más información sobre Modify Image Colors en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!