{"id":1338,"date":"2015-06-23T17:23:31","date_gmt":"2015-06-23T21:23:31","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=1338"},"modified":"2019-11-01T11:42:30","modified_gmt":"2019-11-01T15:42:30","slug":"new-image-batch-processor-app-in-r2015a","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2015\/06\/23\/new-image-batch-processor-app-in-r2015a\/","title":{"rendered":"New image batch processor app in R2015a"},"content":{"rendered":"<div class=\"content\"><p>Nine years ago I wrote a <a href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/06\/06\/batch-processing\/\">blog post<\/a> showing how to do <i>batch processing<\/i> of image files. That is, I showed how to use MATLAB to perform the same operation on a bunch of image files in a particular folder.<\/p><p>The basic procedure is:<\/p><div><ol><li>Get a list of filenames.<\/li><li>Determine the processing steps to follow for each file.<\/li><li>Put everything together in a for loop.<\/li><\/ol><\/div><p>The processing steps for each file typically looked like this:<\/p><div><ol><li>Read in the data from the file.<\/li><li>Process the data.<\/li><li>Construct the output filename.<\/li><li>Write out the processed data.<\/li><\/ol><\/div><p>I showed a sample processing loop that cropped and resized a bunch of images the same way:<\/p><pre>files = dir('*.JPG');\r\nfor k = 1:numel(files)\r\n   rgb = imread(files(k).name);\r\n   rgb = rgb(1:1800, 520:2000, :);\r\n   rgb = imresize(rgb, 0.2, 'bicubic');\r\n   imwrite(rgb, ['cropped\\' files(k).name]);\r\nend<\/pre><p>You can still do it exactly this way today, of course, in 2015. But you really might want to use the new Image Batch Processor App instead:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/steve\/files\/imagebatchprocessor_spec_fcn.png\" alt=\"\"> <\/p><p>This is a very nice app that was just added to the Image Processing Toolbox in R2015a (released earlier this year, in March). If you look at the tool strip from left to right, you can see the entire workflow laid out for you.<\/p><div><ol><li>Load the images. You can specify the folder containing your data.<\/li><li>What function do you want to run on each image? You can specify an existing function, or you can let the app make a shell function for you, and then you can fill in the details.<\/li><li>Where do you want to put the output? Here you can say you just want to overwrite the input files. (Be careful!)<\/li><li>Do you want to use a parallel cluster?<\/li><li>Do you want to process all the files, or just a selection?<\/li><li>Do you want to generate some code so you can automate the entire process?<\/li><\/ol><\/div><p>I encourage you to give it a try. The toolbox documentation gives you <a href=\"https:\/\/www.mathworks.com\/help\/images\/batch-processing-using-the-image-batch-processor-app.html\">more details for getting started<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_54f862d941ab43e59f6134aa811b8620() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='54f862d941ab43e59f6134aa811b8620 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 54f862d941ab43e59f6134aa811b8620';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_54f862d941ab43e59f6134aa811b8620()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2015a<br><\/p><\/div><!--\r\n54f862d941ab43e59f6134aa811b8620 ##### SOURCE BEGIN #####\r\n%%\r\n% Nine years ago I wrote a\r\n% <https:\/\/blogs.mathworks.com\/steve\/2006\/06\/06\/batch-processing\/ blog post>\r\n% showing how to do _batch processing_ of image files. That is, I showed how to\r\n% use MATLAB to perform the same operation on a bunch of image files in a\r\n% particular folder.\r\n%\r\n% The basic procedure is:\r\n%\r\n% # Get a list of filenames.\r\n% # Determine the processing steps to follow for each file.\r\n% # Put everything together in a for loop.\r\n%\r\n% The processing steps for each file typically looked like this:\r\n%\r\n% # Read in the data from the file.\r\n% # Process the data.\r\n% # Construct the output filename.\r\n% # Write out the processed data.\r\n%\r\n% I showed a sample processing loop that cropped and resized a bunch of images\r\n% the same way:\r\n%\r\n%  files = dir('*.JPG');\r\n%  for k = 1:numel(files)\r\n%     rgb = imread(files(k).name);\r\n%     rgb = rgb(1:1800, 520:2000, :);\r\n%     rgb = imresize(rgb, 0.2, 'bicubic');\r\n%     imwrite(rgb, ['cropped\\' files(k).name]);\r\n%  end\r\n%\r\n% You can still do it exactly this way today, of course, in 2015. But you really\r\n% might want to use the new Image Batch Processor App instead:\r\n%\r\n% <<https:\/\/blogs.mathworks.com\/steve\/files\/imagebatchprocessor_spec_fcn.png>>\r\n%\r\n% This is a very nice app that was just added to the Image Processing Toolbox in\r\n% R2015a (released earlier this year, in March). If you look at the tool strip\r\n% from left to right, you can see the entire workflow laid out for you.\r\n%\r\n% # Load the images. You can specify the folder containing your data.\r\n% # What function do you want to run on each image? You can specify an existing\r\n% function, or you can let the app make a shell function for you, and then you\r\n% can fill in the details.\r\n% # Where do you want to put the output? Here you can say you just want to\r\n% overwrite the input files. (Be careful!)\r\n% # Do you want to use a parallel cluster?\r\n% # Do you want to process all the files, or just a selection?\r\n% # Do you want to generate some code so you can automate the entire process?\r\n%\r\n% I encourage you to give it a try. The toolbox documentation gives you\r\n% <https:\/\/www.mathworks.com\/help\/images\/batch-processing-using-the-image-batch-processor-app.html\r\n% more details for getting started>.\r\n##### SOURCE END ##### 54f862d941ab43e59f6134aa811b8620\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/steve\/files\/imagebatchprocessor_spec_fcn.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Nine years ago I wrote a blog post showing how to do batch processing of image files. That is, I showed how to use MATLAB to perform the same operation on a bunch of image files in a particular... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2015\/06\/23\/new-image-batch-processor-app-in-r2015a\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":1339,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[154,76,156,164,162],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1338"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=1338"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1338\/revisions"}],"predecessor-version":[{"id":1343,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/1338\/revisions\/1343"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media\/1339"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=1338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=1338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=1338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}