필터 지우기
필터 지우기

Loading multiple images in App Designer

조회 수: 1 (최근 30일)
승곤 유
승곤 유 2022년 5월 16일
댓글: Walter Roberson 2023년 10월 18일
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
Walter Roberson
Walter Roberson 2023년 10월 18일
What is the purpose of the addpath call?

댓글을 달려면 로그인하십시오.

답변 (1개)

T.Nikhil kumar
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 ‘Img4D array.
I would also suggest you to consider preallocation for the ‘Img’ matrix to have better performance.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by