Batch processing and storing in individual files

3 vues (au cours des 30 derniers jours)
shivasakthi
shivasakthi le 10 Sep 2012
I am processing image files in batches and would like to store the result in individual files. I am making use of batch processing file available in matlab. My code goes like this:
p = which('interphase 1.bmp');
filelist = dir([fileparts(p) filesep '*.bmp']);
fileNames = {filelist.name}'
fileNames =
'interphase 1.bmp'
'interphase 10.bmp'
'interphase 11.bmp'
'interphase 12.bmp'
'interphase 13.bmp'
'interphase 14.bmp'
'interphase 2.bmp'
'interphase 3.bmp'
'interphase 4.bmp'
'interphase 5.bmp'
'interphase 6.bmp'
'interphase 7.bmp'
'interphase 9.bmp'
I = imread(fileNames{1});
imshow(I)
filtering = medfilt2(I);
figure, imshow(filtering)
FilteringSequence = batchProcessFiles(fileNames,@medfilt2);
In the original matlab file, they have made use of implay to play the sequence of batch processed files where they have asked to modify the "parfor" loop inside the "batchProcessFiles" function for storing the data as individual files. I would like to store the results in individual files for further processing. Kindly help me with the modification code for the "parfor" loop so that i can store and process each filtered file individually. Thanks for your response in advance.
  2 commentaires
Edric Ellis
Edric Ellis le 10 Sep 2012
Does the original code use a FOR loop that you're trying to convert to PARFOR? What happens if you try to convert it?
shivasakthi
shivasakthi le 12 Sep 2012
Dear sir, This is the original code: function segmentedCellSequence = batchProcessFiles(fileNames,fcn) %batchProcessFiles Process image files. % SEQUENCE = batchProcessFiles(FILENAMES,FCN) loops over all the files % listed in FILENAMES, calls the function FCN on each of them, and combines % the results in SEQUENCE. FCN is a function handle for a function with % signature: B = FCN(A). % % Supports batch processing demo, ipexbatch.
% Copyright 2007-2009 The MathWorks, Inc.
I = imread(fileNames{1});
[mrows,ncols] = size(I); nImages = length(fileNames);
segmentedCellSequence = zeros(mrows,ncols,nImages,class(I));
parfor (k = 1:nImages)
I = imread(fileNames{k});
segmentedCellSequence(:,:,k) = fcn(I);
end The function batchProcessFiles uses parfor to process each image independently. This works like a regular for loop but can take advantage of multiple processors if you have the Parallel Computing Toolbox software as described below. Now we can call batchProcessFiles to apply the cell detection algorithm to each file.
segmentedCellSequence = batchProcessFiles(fileNames,@batchDetectCells); implay(segmentedCellSequence)
instead of returning the segmented image data in one large array, i need to modify the body of the *parfor loop in batchProcessFiles.m *to write each segmented image to a new file. help me with the process

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 10 Sep 2012
  1 commentaire
shivasakthi
shivasakthi le 12 Sep 2012
Dear sir, I link you have given has answered how to process a batch of files but not on how to apply a function to that batch of files. I need to apply a function like filtering to a set of 200 images. kindly help me in modifying this code so that i can store the results to individual files for further processing: p = which('interphase 1.bmp'); filelist = dir([fileparts(p) filesep '*.bmp']); fileNames = {filelist.name}'
fileNames =
'interphase 1.bmp'
'interphase 10.bmp'
'interphase 11.bmp'
'interphase 12.bmp'
'interphase 13.bmp'
'interphase 14.bmp'
'interphase 2.bmp'
'interphase 3.bmp'
'interphase 4.bmp'
'interphase 5.bmp'
'interphase 6.bmp'
'interphase 7.bmp'
'interphase 9.bmp'
I = imread(fileNames{1});
imshow(I)
filtering = medfilt2(I);
figure, imshow(filtering)
FilteringSequence = batchProcessFiles(fileNames,@medfilt2);
SEQUENCE = batchProcessFiles(FILENAMES,FCN) loops over all the files % listed in FILENAMES, calls the function FCN on each of them, and combines % the results in SEQUENCE. FCN is a function handle for a function with % signature: B = FCN(A). % % Supports batch processing demo, ipexbatch.
% Copyright 2007-2009 The MathWorks, Inc.
I = imread(fileNames{1});
[mrows,ncols] = size(I); nImages = length(fileNames);
segmentedCellSequence = zeros(mrows,ncols,nImages,class(I));
parfor (k = 1:nImages)
I = imread(fileNames{k});
segmentedCellSequence(:,:,k) = fcn(I);
end The function batchProcessFiles uses parfor to process each image independently. This works like a regular for loop but can take advantage of multiple processors if you have the Parallel Computing Toolbox software as described below. Now we can call batchProcessFiles to apply the cell detection algorithm to each file.
segmentedCellSequence = batchProcessFiles(fileNames,@batchDetectCells); implay(segmentedCellSequence)
instead of returning the segmented image data in one large array, i need to modify the body of the *parfor loop in batchProcessFiles.m *to write each segmented image to a new file. help me with the process

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by