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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Image Analyst
Image Analyst il 10 Lug 2014
Modificato: Image Analyst il 10 Lug 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 Commenti
Image Analyst
Image Analyst il 10 Lug 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 il 11 Lug 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Read, Write, and Modify Image in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by