フィルターのクリア

How to make script look for specific files for processing?

1 回表示 (過去 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 Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by