Clear Filters
Clear Filters

How do I read the image of the half of a sequence of images?

2 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 10 Jul 2014
Edited: Image Analyst on 10 Jul 2014
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 Comments
Image Analyst
Image Analyst on 10 Jul 2014
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?');
Karina
Karina on 11 Jul 2014
NET.addAssembly('System.Speech');
obj = System.Speech.Synthesis.SpeechSynthesizer;
obj.Volume = 100;
Speak(obj,'I think so, thank you very much!');
Thank you Image Analyst. You always really help me! Regards

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!