**Appendix B**

As can be seen from Figure A1, the system presents a modular architecture, composed of several interacting objects or classes. The structure of the application has been designed to ensure a two-layer division—the presentation layer and the status of the business logic. The first layer includes the Java classes that play the role of activities, having the task to show the screens with the GUI and to define the various behaviors of the application, based on the user interaction with the interfaces. The second layer belongs to the Java classes that implement the algorithm proposed in the previous paragraphs and accesses the file system of the smartphone, playing the role of operating classes for the back-end. Below are described the main modules and methods.

**Figure A1.** Software architecture.

MainActivity represents the main class, as well as the activity that is activated by the Android operating system, invoking the onCreate method. Other methods of MainActivity are fastCapture, multiCapture, galleryOpen, and infoHowto, invoking other activities that are part of the application, described below. Additionally, quit and checkPermissions methods are invoked, respectively, to close the application and to check if permissions have been granted to allow the app to access the device memory, take pictures, and use the Internet connection.

FastCaptureActivity and Capture are both part of the presentation layer, and represent, respectively, the function that allows you to take a single photo and immediately extract the cellular elements to send, and one of its internal classes. FastCaptureActivity, after its invocation with the onCreate method, uses its inner-class Capture to activate the camera and display the frames captured by the latter, with which it will be possible to capture the digital images to submit to the extraction function. The first of the main methods of the Capture class is takePicture that acquires the photo and, after converting it from Bitmap type to Mat type, it stores it in a variable that will be the input of the algorithm of detection and extraction.

MultiCaptureActivity and MultiCapture, are similar to the previous classes with the only difference being that the MultiCaptureActivity class allows you to take any number of photos, acquired thanks to the MultiCapture class that temporarily saves them in a data structure (ArrayList) and provides them all together with the detection and extraction algorithm.

GalleryActivity and FullScreenActivity deal with the visualization of the cells extracted from the algorithm. In particular, the first deals with the loading of the images extracted, accessing the memory of the device, and their visualization in a gallery, in which all the previews of the extracted cells that will be selectable and shareable will be displayed. In particular, the shareImages and deleteImage methods are used, respectively, to share the selected cells and to delete them from the device memory. The reloadAdapter method is used to update the gallery screen after sharing or deleting images, simply reloading the images from the memory. FullScreenActivity is the activity that is invoked by GalleryActivity every time you press on a preview. This activity allows the full screen display of the selected cell.

InfoActivity displays a screen with instructions on how to use the application correctly.

WatershedSegmentation and MultiWatershed are the internal classes belonging, respectively, to FastCaptureActivity and MultiCaptureActivity activities. They are instantiated every time the process of identification and the extraction of cellular elements from the photo(s) taken are started. Their most important methods are detected, which represents the process related to the identification of the cells, proposed in the algorithm described above, the extract method that extracts the elements identified by the previous method, creating a new image for each of them representing only the region of interest that circumscribes the cell, the enlargeRoi method that allows the user to enlarge the area of the region of interest around the cell, and finally the performGammaCorrection method, invoked by the detect method for the gamma correction. Both classes access the smartphone file system and save the cells in the /Pictures/Segmentation/Session directory. This path will be created automatically the first time you launch the application.

Each of the above activities is associated with a layout defined in XML.
