Skip to content
Snippets Groups Projects

Scattering Images

In this repository, you can find all the scripts (Python and Matlab) and example files (csv, images...) for being able to classify, infer parameters and process images. In order to achieve it, deep learning and image processing techniques are used.

The repository is organized in 4 folders:

python

All the scripts in this folder, should also be in the same directory in order to be usable.

Description of files are listed below:

  • img_process: functions for making real images more alike to simulated ones.
  • label_classify_image_folder: adaptation of label_image. It serves to the same purpose but for all the images in a folder (user specifies it). Given a prediction for each image, it classifies all of them in "subfolders tree" following the prediction.
  • main_SANS: it execute several scripts sequentially to generate images (save_sim_sphere.m), classify them (label_classify_image_folder.py), plot distribution of images based on radius, wavelength, distance and prediction (plot_results.py), suggest new instrumental params to transform an image into the desired type (regression_radius_multip.py), generate new images (create_suggested_images.m) and classify them (label_classify_image_folder.py).
  • misclassified_images: script that shows the user the images which CNN has given a label different to the one it has assigned at the beginning. User should decide inputting a letter by keyboard if he/she wants to move or not the image to the folder, CNN has suggested.
  • move_files: several functions to move, extract information of the name and classify files.
  • plot_results: given a directory, plot the distribution of images in it based on radius, wavelength, distance and prediction.
  • regression_radius_deep:
  • regression_radius_multip: reading a results.csv file (see doc_files), it suggest a transformation for all the images in a folder (user specifies it) to convert them into the desired type. As an output, it produce a suggest.csv file.
  • regression_radius_stacked:

Tensorflow scripts:

  • label_image: transfer learning module. Tensorflow. More info in retrain.py.
  • retrain: transfer learning code. It uses a model produced in retrain.py to classify individual images. More info in label_image.py.

matlab

All the scripts in this folder, should also be in the same directory in order to be usable. Among all the scripts, we are going to define the main ones. They call the other scripts in the folder.

  • save_sim_sphere: script developed by ILL scientists to generate simulated scattered images based on instrumental and sample parameters. Next scripts are based on this one.
  • create_suggested_images: create images whose description is specified in suggest.csv.
  • create_img_param: script used in regression_radius_multip.py for generating individual scattered images.

doc_files

It contains template files that are generated in python scripts.

  • results.csv: file (csv format) produced in label_classify_image_folder.py. It contains info of classified images (dist, collimation, wavelength, CNN prediction for this image, and the average prediction). It is used in regression_radius_multip.py and regression_radius_deep.py.
  • suggest.csv: file (csv format). It contains: dist, col, wavelength suggested, and the original radius. It is created in regression_radius_multip.py and it is used in create_suggested_images.m.
  • Original_misclassified.txt: file (txt format) produced in retrain.py when option --print_misclassified_images is active. It is used in misclassified_images.py to reclassify images. You can move the images from their previous ubication to the one that the CNN decides.

imgs

It contains two folders: one with simulated scattered images and other with real ones. All of them follows a Sphere model.

Pay special attention, to simulated file's name. It contains the name and value of parameters that have led to the resulting scattered image.