Group Abstract Group Abstract

Message Boards Message Boards

Best way to repeatedly evaluate code lines?

Posted 4 years ago
POSTED BY: Ehud Behar
2 Replies
Posted 4 years ago

That's a great answer. Thanks a lot!

POSTED BY: Ehud Behar
Posted 4 years ago

Hi Ehud,

Writing a function is the best way to do that. Something like

meanGrayPlot[imageFileName_String] := 
  Import[imageFileName] // ColorConvert[#, "Grayscale"] & // RemoveAlphaChannel // 
  ImageData // Mean // 
  ListPlot[#, PlotLabel -> FileNameTake[imageFileName], ImageSize -> 300] &

Then map it over a list of filenames. I ran it on a directory with some PNG images I had. Change *.png to *.tif and dir to the name of the directory with your images.

FileNames["*.png", dir] // Map[meanGrayPlot] // 
  Partition[#, UpTo[3]] & // Grid[#, Frame -> All] & // 
  Labeled[#, "Mean Graylevel Plots", Top] &

enter image description here

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard