input window in matlab

3 次查看(过去 30 天)
Amal Felhi
Amal Felhi 2021-4-10
评论: Amal Felhi 2021-4-11
Hello everyone, i work with this code:
rep = uigetdir;
Imgs = dir(rep);
thisname = Imgs(3).name;
[path,name,ext]=fileparts(thisname);
ext=strcat('*',ext);
chemin = fullfile(rep,ext);
list = dir(chemin);
nbr_images= numel(list);
for n=1:25
k=dicomread(fullfile(rep, list(n).name));
end;
IM=double(k);
figure(1),,imshow(IM,[]);impixelinfo;
for n=1:25
figure(2),subplot(5,5,n),imshow(IM,[]);
end
IM=dicomread(fullfile(rep, list(1).name))
IM(1,1,numel(list))=0; %extend array to fit all slices
for n=2:numel(list)
IM(:,:,n)=dicomread(fullfile(rep, list(n).name));
end
xi= input('Give the centre X coord : '); % X coord
yi= input('Give the centre y coord : '); % y coord
for n=1:25
intensity=squeeze(IM(xi,yi,:));
figure(3),plot(intensity)
xlabel('Image')
ylabel('Intensité')
title('Courbe de progression du pixel courant')
grid('on');
set(gca,'Xtick',1:1:25);
set(gca,'Ytick',0:10:255);
end
i want to change this two instructions:
xi= input('Give the centre X coord : ');
yi= input('Give the centre y coord : ');
with an input window.
i tried to remplace them with this code :
prompt={'enter value for x','enter value for y'};
dig_title='Input';
num_lines=1;
def={' ',' '};
answer=inputdlg(prompt,dig_title,num_lines,def);
but it didn't work correctly.any help?

采纳的回答

DGM
DGM 2021-4-10
编辑:DGM 2021-4-10
The dialog is the least of the problems. In general:
rep = uigetdir;
Imgs = dir(rep);
thisname = Imgs(3).name;
[path,name,ext]=fileparts(thisname);
ext=strcat('*',ext);
chemin = fullfile(rep,ext);
list = dir(chemin);
nbr_images= numel(list); % you defined it here, why not use it?
% you're reading the images in one at a time into k and overwriting it
% k only contains the last image
for n=1:nbr_images % don't assume there's always 25 files in a directory
k=dicomread(fullfile(rep, list(n).name));
end
% what's the point of recasting k without scaling it?
% imshow doesn't know how to display data that's not scaled for its class
% it just gets overwritten anyway
IM=double(k);
imshow(IM,[]);
impixelinfo;
% what is this supposed to do? This just shows 25 copies of the same image
for n=1:nbr_images % again
subplot(5,5,n),imshow(IM,[]);
end
% i guess it's time to re-read all the files again for some reason?
% but now IM is the first image instead of the last image. nice & confusing
IM=dicomread(fullfile(rep, list(1).name)); % terminate with a semicolon
% idk what's going on here. you're assuming that the first image in an alphabetical sorting
% of the directory contains as many samples per frame as the number of files in the directory
% maybe it's a master set of all images? previews?
IM(1,1,nbr_images)=0;
% but apparently the rest of the images are presumed to have only 1 sample per frame
% otherwise, this will explode the moment it runs across something else
% if file 1 is a master set of all images in the directory, is this
% necessary? does the image content differ? idk.
for n=2:numel(list)
IM(:,:,n)=dicomread(fullfile(rep, list(n).name));
end
xi= input('Give the centre X coord : ');
yi= input('Give the centre y coord : ');
for n=1:nbr_images % again
intensity=squeeze(IM(xi,yi,:));
plot(intensity)
xlabel('Image')
ylabel('Intensité')
title('Courbe de progression du pixel courant')
grid('on');
set(gca,'Xtick',1:1:25);
set(gca,'Ytick',0:10:255);
end
As far as the dialog issue goes, it returns a cell array, so you should just be able to do this:
prompt={'enter value for x','enter value for y'};
dig_title='Input';
num_lines=1;
def={' ',' '};
answer=inputdlg(prompt,dig_title,num_lines,def);
xi=answer{1}
yi=answer{2}
and use the values as needed.
  3 个评论
DGM
DGM 2021-4-11
I forgot to convert the strings. Try this.
xi=str2num(answer{1})
yi=str2num(answer{2})
Also, you're doing this plot in a loop. Nothing in the loop changes. You overwrite the same plot 25 times. Just get rid of the loop.
for n=1:nbr_images % again
intensity=squeeze(IM(xi,yi,:));
plot(intensity)
xlabel('Image')
ylabel('Intensité')
title('Courbe de progression du pixel courant')
grid('on');
set(gca,'Xtick',1:1:25);
set(gca,'Ytick',0:10:255);
end
Amal Felhi
Amal Felhi 2021-4-11
thank you it works but there is another problem that when displaying the images I want to select a point from the impixel info then I put the coordinates in the input window

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by