<jupyter_start><jupyter_text>Sample Jupyter Notebook for WIPP Workflow  Install Python libraries not pre-installed in Polus Notebooks<jupyter_code>!pip install -q opencv-python<jupyter_output><empty_output><jupyter_text>Read image collections from WIPP<jupyter_code># # UNCOMMENT THIS CODE IF RUNNING INTERACTIVELY
# import requests
# api_route = 'http://wipp-backend:8080/api/'
# collections_path = '/opt/shared/wipp/collections/'

# def get_collection_path(collection_name):
#     r = requests.get(api_route + 'imagesCollections/search/findByNameContainingIgnoreCase?name=' + collection_name)
#     if r.status_code==200:
#         collection_id = r.json()['_embedded']['imagesCollections'][0]['id']
#     collection_path = collections_path + collection_id + '/images/'
#     return collection_path

# input_path = get_collection_path('test-data-pyr')
# output_path = '/home/jovyan/output'<jupyter_output><empty_output><jupyter_text>For running as a WIPP Workflow, please set the tags for cell below. Select the cell below and click **Notebook Tools** on the left panel ![Alt text](build.svg). Navigate to **Advanced Tools** -> **Cell Metadata**, then add the following entry:```"tags": [ "parameters" ]```Then all variables in this cell will become input parameters for WIPP. Here we only need paths to input and output image collections<jupyter_code># KEEP THIS CODE UNCOMMENTED WHEN RUNNING AS WIPP WORKFLOW TO SUPPLY IMAGE COLLECTION NAMES
input_path = ''
output_path = ''<jupyter_output><empty_output><jupyter_text>Example codeIn this example we are reading the images from input image collection and write them to output image collection<jupyter_code>import cv2
import os,glob
import numpy as np
#Read all the files(.tif) in the directory using cv2
filenames = glob.glob(os.path.join(input_path, '*.tif'))
images = [cv2.imread(img, cv2.IMREAD_COLOR) for img in filenames]
# Example of saving images to output image collection
for index,img_file in enumerate(images):
    title =  os.path.basename(filenames[index])
    img = cv2.cvtColor(img_file, cv2.COLOR_BGR2GRAY)
    cv2.imwrite(output_path + f"/Output_image_{title}", img)
# # Example of saving data to output image collection
# with open(output_path + '/stats.dat', 'w') as f:
#     for image in images:
#         f.write(f"{image.shape}\n")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10787671232876712, 'fraction_numerical': 0.00684931506849315, 'mean_word_length': 5.583098591549295, 'pattern_counts': {'":': 1, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '447266', 'license': 'MIT', 'n_tokens_mistral': 762, 'n_tokens_neox': 737, 'n_words': 215, 'path': 'python-opencv-io.ipynb', 'repo_name': 'ktaletsk/sample-notebooks-for-wipp-plugin', 'size': '2336'}