How do I read the image of the half of a sequence of images?
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have this code.
Carpeta='C:\Users\karina\Documents\MATLAB\11';
if ~isdir(Carpeta)
errorMensaje = sprintf('Error: La Carpeta no existe:\n%s', Carpeta);
uiwait(warndlg(errorMensaje));
return;
end
filePatron = fullfile(Carpeta, '*.jpg');
jpegFil = dir(filePatron);
Mitad=length(jpegFil)/2;
MitadR=round(Mitad);
A=num2str(MitadR);
base=[A,'.jpg'];
ImagenOriginal=imread(base);
%Convertir a escala de Grises
imOrGris=rgb2gray(ImagenOriginal);
%Versión binaria por el método de Otsu
Ib=graythresh(imOrGris);
BN = im2bw(imOrGris,Ib);
%Se aplica una máscara de 25 x 25 pixeles
Ibmask=medfilt2(BN,[25 25]);
%Se elige la región ROI
iROI=roicolor(Ibmask,1);
imcrop(iROI)
But my series name is 'MVI_1211 X.jpg' where X is a number from 1 to 45. Then what I want is to read only the image in the middle, in this case the image 23. It would be 'MVI_1211 23.jpg' instead of 23.jpg which I don't have. I don't want write MVI_1211 to complete the name because it has to function with different folders and series. Thank you for your time. Regards.
0 个评论
采纳的回答
Image Analyst
2014-7-10
编辑:Image Analyst
2014-7-10
Call dir(), sort(), etc.
filenames = dir('MVI_1211*.jpg');
% Extract out just the names into a cell array.
names = struct2cell(filenames);
names = lower(names(1,:))
% Then call sort()
sortedList = sort(names)
% Then get the number of strings. Then get the halfway item
middleIndex = floor(length(sortedList)/2)
% Get the middle filename.
middleFileName = sortedList(middleIndex)
2 个评论
Image Analyst
2014-7-10
And then (for fun)
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj,'MATLAB is an awesome programming language, dont you think, care reena?');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!