Loading multiple images in App Designer
5 次查看(过去 30 天)
显示 更早的评论
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 个)
T.Nikhil kumar
2023-10-18
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!