How to make script look for specific files for processing?

조회 수: 2 (최근 30일)
Bryant
Bryant 2014년 7월 2일
댓글: Bryant 2014년 7월 3일
Hi all,
I was wondering if there was a way for my script to look for specific files to import (jpg files) so it can crop multiple images selected.
%Insert file names (without extensions) for processing
for LFAfile={'0W_1pc','0W_2pc','0W_3pc','0NoC_1pc','0NoC_2pc','0NoC_3pc'};
%Add the file extension and look for the file
if(exist(strcat(LFAfile{1}, '.jpg'),'file'))
LFA = imread(strcat(LFAfile{1}, '.jpg'));
%Uncropped set to 0 means that the image must still be manually
%cropped
if(uncropped==0)
%Image will appear in upper panel.
%Manually crop by drawing a box around the test and control lines
%Make sure the control line is in the left half of the crop window
%and the test line is in the right half of the crop window
subplot(3,1,1);
LFAGray = imcrop(rgb2gray(LFA), [46.5 3.5 219 31]);
close all;
else
LFAGray = rgb2gray(LFA);
end

채택된 답변

dpb
dpb 2014년 7월 2일
Sure, if you can develop the pattern, you can generalize it...
for LFAfile={'0W_1pc','0W_2pc','0W_3pc','0NoC_1pc','0NoC_2pc','0NoC_3pc'};
if(exist(strcat(LFAfile{1}, '.jpg'),'file'))
It depends on whether there are other files of similar naming that are not wanted or not as to how much effort you need. If it's a subdirectory that's full of .jpg files that need be done, then the simplest is just
d=dir('*.jpg');
for i=1:length(d)
LFA = imread(d(i).name);
...
which eliminates the need to test for existance, etc., because dir won't include it if it doesn't.
Now the next most restrictive case in your example of names is that they all begin w/ 'O', so add that to the wildcard string--
d=dir('O*.jpg');
Next would require making up the two cases of 'OW*' and 'ON*' or perhaps it's the pc at the end of the name that is unique; no way for us to know that. There's also the alternative of getting the full array of .jpg files and then excluding ones not wanted therefrom. As many alternatives as you can dream up, depending on what the actual rules are for who is/isn't to be in the process list.
  댓글 수: 3
dpb
dpb 2014년 7월 2일
Of course you could, but uigetfile is probably more appropriate since it has multi-select capability (that otomh I don't think uiopen has). You can (and will :) ), of course, check the doc's for the details...
Bryant
Bryant 2014년 7월 3일
Thanks for helping a noob out dpb! (:

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Sequences and Batch Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by