Skip to content

Improve visualisation #5

@grzanka

Description

@grzanka

Take a look at the experiment I once made with google colab. I've uploaded a single file COSK_CuCl.tif and wanted to inspect what's inside.
Here is a prompt I've arrived after couple of iterations:

# prompt: plot image with colorscale to the right with ticks every 100, set max pixel value to 99% percentile of the data,
# add gaussian filter with kernel size 5, use such pallete that pixels with value zero are transparent,
# while the most intensive values gets color red, values around 500 with color green,
# add iso-values lines for every 100, isolines should have a text with isoline value

Here is the generated code:

from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage import gaussian_filter

file_path = Path('COSK_CuCl.tif')
if file_path.exists():
    image = plt.imread(file_path)

    # Gaussian filter
    image_filtered = gaussian_filter(image, sigma=2.5)

    # Calculate the 99th percentile
    max_pixel_value = np.percentile(image_filtered, 99)

    # Create a custom colormap
    import matplotlib.colors as mcolors
    cmap = mcolors.LinearSegmentedColormap.from_list("custom_cmap", [(0,0,0,0),(0,1,0,1),(1,0,0,1)], N=256)

    # Plot the image
    fig, ax = plt.subplots(figsize=(8, 6))
    im = ax.imshow(image_filtered, cmap=cmap, vmax=max_pixel_value, origin='lower')

    # Add colorbar
    cbar = plt.colorbar(im, ticks=np.arange(0, max_pixel_value + 100, 100))
    cbar.ax.set_ylabel('Pixel Value', rotation=270, labelpad=15)

    # Add isolines
    CS = ax.contour(image_filtered, levels=np.arange(0, max_pixel_value + 100, 100), colors='black', linewidths=0.5)
    ax.clabel(CS, inline=1, fontsize=8, fmt='%1.0f')

    plt.title("Image with Isolines and Colorbar")
    plt.show()
else:
    print(f"File not found: {file_path}")

and the results:

Image

The important data processing which I would like to implement in rustoscope is:

  • (optional) contour lines, calculated in Rust ? on user-defined levels ?

Sub-issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions