Hi everyone,
I’m a non-CS background student, attempting to use the very cool feature from Wolfram, the function ImageContents[ ] that identifies objects and elements of an image.
For example: if i use the function for an image of a sheep, sitting in a grassland, it will identify where it is located in the image, the dimensions of the sheep and the probability that it is an actual sheep.
However, I’m not sure how to extract this output and save it for reference. I’ve tried copy-paste(which didn’t really work) and even if it did, I’m afraid I have too many images(about 500 images) to do that. Is there a function or feature that can store this output in a file? A simple excel file should do the trick since it is basically saving coordinates and numbers. I’ve done the tutorials for image processing, but I don’t think saw anything related to this issue.
Any help or advice is appreciated. Thanks in advance.
ImageContents returns its results as a Dataset, which is essentially a list of nested associations. To query part of a list, you use the Part[] syntax, and to query part of an association, you can use the name of the key you want to query.
ds = ImageContents[(my image)];
ds[[1]] (*returns the first association in the dataset*)
ds[[1]]["Image"] (*returns the element of the association with key "Image"*)
Then if you have multiple contents in the image, you can iterate over the parts.
I am trying to export the outputs of ImageContents function to an external file to use it for future purposes. However, when I use the Export[] function, it exports the pixel values for the image as a Numeric Array, instead of the output (concept and probability) from the function.
The problem is that the Dataset has images in it. If you keep the images, you can export them as CSV but they will be in Numeric Array form (which can be recovered later as an Image).
Look at the help for Dataset – it discusses the Export formats. (Dataset—Wolfram Documentation) search for Exporting Datasets.
If your goal is to export it and import it later to Mathematica than you want the “MX” format. This will preserve everything.
You can also get a complete Association by doing Normal[] on the Dataset. If you strip off the image column you can export it as a textual CSV.