Multi-channel Image Support- Week4

Tarun Jain
3 min readJun 30, 2023

--

GSoC23 caMicroscope

In this article, I will share my progress done in Google Summer of Code 2023 at caMicroscope during Week 4.

Progress Summary

In the past weeks [Week 1, Week 2, Week 3] I spent time researching to find an optimal way to efficiently convert the multi-channel medical images into RGB channels. In this phase, I explored a dataset having 4 channels and multiple bands known as Hyperspectral Images.

Now moving to the next phase where this methodology is to be integrated as a service. I worked to build a web interface where users can upload medical images and can visualize the RGB output.

Before directly jumping into the web interface I learnt how to use Postman. Coming from an electronics background, I never used Postman before. With Postman I tried the GET and POST method to upload an image and get the response. Also, I learnt how to build Rest-Ful APIs.

Implementation

After the discussion with the mentor, I moved on with the implementation of the multi-channel implementation using Python Flask. I built a basic CSS and HTML where the user can upload the image. In order to stay in sync with the caMicroscope codebase, I referred SlideLoader functionality to develop the same logic with Multi-channel Image support.

Once the image is uploaded, I run my model or algorithm model developed in Week 3. The combination of different image extensions is pending and will be covered in Week 5.

@app.route('/', methods=['GET', 'POST'])
def upload_image():
if request.method == 'POST':
if 'image' not in request.files:
return "No image uploaded", 400

image_file = request.files['image']
image_path = os.path.join(app.config['TEMP_FOLDER'], image_file.filename)

image_file.save(image_path)
return redirect(url_for('convert_channel', filename=image_file.filename))

return render_template('index.html')

Results

Simple Webpage
@app.route('/rgb/<filename>', methods=['GET'])
def convert_channel(filename):
image_path = os.path.join(app.config['TEMP_FOLDER'], filename)
print(image_path)
image = Image.open(image_path)

final_image = model.RGB(image)

image_data = BytesIO()
final_image.save(image_data, format='JPEG')
image_data.seek(0)

return send_file(image_data, mimetype='image/jpeg')

Results

Output

Further improvements

Medical images take a large size to upload. In order to maintain less loading time and provide a better user experience, Birmingham Ryan(my mentor) suggested a few additions.

  • Implementation of IIIF API. The IIIF API specifies a web service that returns an image in response to a standard HTTP or HTTPS request. The URL can specify the region, size, rotation, quality, and format of the requested image.
  • Usage of OpenSeadragon. OpenSeadragon has added support for IIIF thanks to several of the authors of its specification.
  • Flask-IIIF is a Flask extension permitting easy integration with the International Image Interoperability Framework (IIIF) API standards.

--

--

Tarun Jain

Youtube: AIWithTarun || ML @AIPlanet || GSoC'24 RedHen Lab ||GSoC'23 @caMicroscope || GDE in ML