Loading multiple images in App Designer
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am trying to open a new figure window in App Designer and check multiple images using the slider.
addpath('C:')
direc = 'C:\Users\User\Desktop\0513 유승곤\예제 이미지';
filename = dir(fullfile(direc,'*.jpg'));
for i=1:length(filename)
Img(:,:,i,:) = (imread(fullfile(direc,filename(i).name)));
end
MinV = 0;
MaxV = max(Img(:));
LevV = (double( MaxV) + double(MinV)) / 2;
Win = double(MaxV) - double(MinV);
W = Win; L = LevV;
Rmin = L - (W/2);
Rmax = L + (W/2);
if (Rmin >= Rmax)
Rmax = Rmin + 1;
end
sno = size(Img,3); % number of slices
S = round(sno/2);
FigPos = get(gcf,'Position');
S_Pos = [30 45 uint16(FigPos(3)-100)+1 20];
clf
axes('position',[0,0.2,1,0.8]), imshow(squeeze(Img(:,:,S,:)), [Rmin Rmax])
shand = uicontrol('Style', 'slider','Min',1,'Max',sno,'Value',S,'SliderStep',[1/(sno-1) 10/(sno-1)],'Position', S_Pos,'Callback', {@SliceSlider, Img});
function SliceSlider (hObj,event, Img)
sno = size(Img,3); % number of slices
S = round(get(hObj,'Value'));
MinV = 0;
MaxV = max(Img(:));
LevV = (double(MaxV) + double(MinV)) / 2;
Win = double(MaxV) - double(MinV);
W = Win; L = LevV;
Rmin = L - (W/2);
Rmax = L + (W/2);
if (Rmin >= Rmax)
Rmax = Rmin + 1;
end
set(get(gca,'children'),'cdata',squeeze(Img(:,:,S,:)))
caxis([Rmin Rmax])
% if sno > 1
% set(stxthand, 'String', sprintf('Slice# %d / %d',S, sno));
% else
% set(stxthand, 'String', '2D image');
% end
end
<< Img(:,:,i,:) = (imread(fullfile(direc,filename(i).name))); >>
However, the error continues to occur saying that the value cannot be assigned because the left and right sides have different sizes. What can I do to solve this problem?
1 comentario
Respuestas (1)
T.Nikhil kumar
el 18 de Oct. de 2023
Hello,
As per my understanding, you want to open a slider with multiple images in a new figure window but are facing an error regarding difference in sizes in an array.
This error occurs where you're trying to store multiple 2D images from your image directory into the ‘Img’ 4D matrix, and the dimensions of these images might not match.
I suggest you to ensure that all the images in your images directory are of the same dimensions before populating your ‘Img’ 4D array.
I would also suggest you to consider preallocation for the ‘Img’ matrix to have better performance.
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Develop Apps Using App Designer 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!