how can I use the image region analyzer for multiple images?

1 view (last 30 days)
I have been using the image region analyzer app for one image at a time, but I have a series of images that need to be processed, if there were any solution to make all of images faster ? i have more than 10000 image !!

Answers (1)

Image Analyst
Image Analyst on 3 Apr 2021
See the FAQ:
In the inside of the loop, put a call to your custom image analysis function and pass it the image.
  4 Comments
hussain abdelaziz
hussain abdelaziz on 7 Apr 2021
your code not work for me that work for me but i need to save it as excel sheet
function result = batchmyimfcn(inDir, outDir)
%batchmyimfcn Batch process images using myimfcn
% RESULT = batchmyimfcn(INDIR, OUTDIR) processes each file in INDIR
% using the function myimfcn.
%
% The following fields from the output of myimfcn are written with their
% corresponding file format to the output directory OUTDIR:
%
% The following fields are returned in the table RESULT
% bw
%
% Auto-generated by imageBatchProcessor app on 24-Sep-2015
%----------------------------------------------------------
if(nargin<2)
outDir = '';
end
if(nargin<1)
inDir = 'E:\2حسين ماجستير صور\ge 128\دولفين 128\Series_003_TEST-1 K.V 80 ma140\binary';
end
includeSubdirectories = true;
% Fields to place in result
workSpaceFields = {
'bw'
};
% Fields to write out to files. Each entry contains the field name and the
% corresponding file format.
fileFieldsAndFormat = {
};
% All extensions that can be read by IMREAD
imreadFormats = imformats;
supportedExtensions = [imreadFormats.ext];
% Add dicom extensions
supportedExtensions{end+1} = 'dcm';
supportedExtensions{end+1} = 'ima';
supportedExtensions = strcat('.',supportedExtensions);
% Allow the 'no extension' specification of DICOM
supportedExtensions{end+1} = '';
% Create a image data store that can read all these files
imds = datastore(inDir,...
'IncludeSubfolders', includeSubdirectories,...
'Type','image',...
'FileExtensions',supportedExtensions);
imds.ReadFcn = @readSupportedImage;
% Initialize output (as struct array)
result(numel(imds.Files)) = struct();
% Initialize fields with []
for ind =1:numel(workSpaceFields)
[result.(workSpaceFields{ind})] = deal([]);
end
% Process each image using myimfcn
for imgInd = 1:numel(imds.Files)
inImageFile = imds.Files{imgInd};
% Output has the same sub-directory structure as input
outImageFileWithExtension = strrep(inImageFile, inDir, outDir);
% Remove the file extension to create the template output file name
[path, filename,~] = fileparts(outImageFileWithExtension);
outImageFile = fullfile(path,filename);
try
% Read
im = imds.readimage(imgInd);
% Process
oneResult = myimfcn(im);
% Accumulate
for ind = 1:numel(workSpaceFields)
% Only copy fields specified to be returned in the output
fieldName = workSpaceFields{ind};
result(imgInd).(fieldName) = oneResult.(fieldName);
end
% Include the input image file name
result(imgInd).fileName = imds.Files{imgInd};
% Write chosen fields to image files only if output directory is
% specified
if(~isempty(outDir))
% Create (sub)directory if needed
outSubDir = fileparts(outImageFile);
createDirectory(outSubDir);
for ind = 1:numel(fileFieldsAndFormat)
fieldName = fileFieldsAndFormat{ind}{1};
fileFormat = fileFieldsAndFormat{ind}{2};
imageData = oneResult.(fieldName);
% Add the field name and required file format for this
% field to the template output file name
outImageFileWithExtension = [outImageFile,'_',fieldName, '.', fileFormat];
try
imwrite(imageData, outImageFileWithExtension);
catch IMWRITEFAIL
disp(['WRITE FAILED:', inImageFile]);
warning(IMWRITEFAIL.identifier, IMWRITEFAIL.message);
end
end
end
disp(['PASSED:', inImageFile]);
catch READANDPROCESSEXCEPTION
disp(['FAILED:', inImageFile]);
warning(READANDPROCESSEXCEPTION.identifier, READANDPROCESSEXCEPTION.message);
end
end
result = struct2table(result,'AsArray',true);
end
function img = readSupportedImage(imgFile)
% Image read function with DICOM support
if(isdicom(imgFile))
img = dicomread(imgFile);
else
img = imread(imgFile);
end
end
function createDirectory(dirname)
% Make output (sub) directory if needed
if exist(dirname, 'dir')
return;
end
[success, message] = mkdir(dirname);
if ~success
disp(['FAILED TO CREATE:', dirname]);
disp(message);
end
end
Image Analyst
Image Analyst on 7 Apr 2021
I don't use that built-in app on the tool ribbon so I don't know what kind of output it uses.. I write my own stuff using toolbox functions.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!