vendredi 3 avril 2026

Using Filter2D with Rebol-OpenCV

 Rebol-OpenCV (https://github.com/Oldes/Rebol-OpenCV) Filter2D is really fantastic for creating various filters on image.

filter2D: [
"Convolves an image with the kernel."
src    [handle!] "cvMat"
dst    [handle! none!] "cvMat"
ddepth [integer!] "desired depth of the destination image"
kernel [handle!] "convolution kernel (or rather a correlation kernel), a single-channel floating point matrix"
anchor [pair! integer!] "position of the anchor within the element"
delta  [number!] "value added to the filtered pixels before storing them in dst"
/border "border mode used to extrapolate pixels outside of the image"
type [integer!] "one of: [0 1 2 4 5 16]"
]

This is an example of creating a Kuwahara_filter

#!/usr/local/bin/r3
Rebol [
]
;--https://en.wikipedia.org/wiki/Kuwahara_filter
cv: import opencv
with cv [
    src: imread/with "../images/mandrill.jpg" -1 ;--(IMREAD_UNCHANGED)
    dst: Matrix :src ;--create a matrix
    ;--using Rebol vector type for a 3x3 kernel
    vec: #(f32! [-0.5 1.5 -0.5 1.5 -3.0 1.5 -0.5 1.5 -0.5]) ;--sum = 1
    filter: Matrix [CV_32FC1 3x3 :vec] ;--a 3x3 kernel
    filter2D :src :dst -1 :filter -1x1 0 ;-1 same image depth
    ;--show result
    imshow/name src "Source"
    imshow/name dst "Kuwahara"
    moveWindow "Source"  0x0
    moveWindow "Kuwahara" 260x0
    waitKey 0
    destroyAllWindows

]

The trick is to use vector datatype implemented by Oldes to create the kernel used by the filter2D function.
The result for the Kuwahara_filter:


You can find here https://github.com/ldci/R3_OpenCV_Samples/tree/main/image_filtering a lot of examples for generating filters on image.

vendredi 19 décembre 2025

A simple GUI for Rebol3

Rebol3, developed by Oldes (https://github.com/Oldes/Rebol3), is improving day by day. Unfortunately, Rebol3 does not yet have a VID (except for Windows as a proof of concept), which means that attractive interfaces cannot yet be created. 
Fortunately, Oldes added a nice modules management to Rebol3, which allows this problem to be overcome. 
In this code, we use two modules:
The idea is as follows: we use the Blend2D module to create the interface for our application and the OpenCV module to display the result. 
With Blend2D module, I created five buttons (simple blend2D boxes). Each button is associated with a Rebol3 function that will execute when the button is clicked. Button 1 calls the loadImage function, which allows you to select an image and display it. Buttons 2 and 3 call the convertTo function, which displays the image in grayscale or in HSV color space. Button 4 displays the original image and button 5 exits the application.
Now, the question is how to associate mouse movements with different buttons. Blend2D does not have a mouse manager, which is where the OpenCV module comes in.

Oldes has introduced a mouse event handler into the OpenCV module for these events:
  • MOUSEMOVE
  • LBUTTONDOWN
  • RBUTTONDOWN
  • MBUTTONDOWN
  • LBUTTONUP
  • RBUTTONUP
  • MBUTTONUP
  • LBUTTONDBLCLK
  • RBUTTONDBLCLK
  • MBUTTONDBLCLK
  • MOUSEWHEEL
  • MOUSEHWHEEL
With the cv/setMouseCallback function, we can retrieve the event type, the x and y position of the mouse, and the event flag. We also obtain the mouse position as a pair! x y.

;--OpenCV mouse callback in context
ctx: context [
    on-mouse-click: func [
        type  [integer!]
        x     [integer!]
        y     [integer!]
        flags [integer!]
    ][
    pos: mcb/pos ;--mouse position as a pair!
        if type == cv/EVENT_LBUTTONDOWN [
        if pos/y < 20 [
        case [
        all [pos > 0x0 pos < 80x20]   [loadImage]         ;--button 1
        all [pos > 80x0 pos < 160x20] [if isLoaded? [convertTo/GS fileName]]        ;--button 2
        all [pos > 160x0 pos < 240x20][if isLoaded? [convertTo/HSV fileName]]    ;--button 3
        all [pos > 240x0 pos < 320x20][showSource]    ;--button 4
        all [pos > 320x0 pos < 400x20][quit] ;--button 5
        ]
        ]
        ]
    ]
]

In the on-mouse-click function, we first check that the mouse is within the button area. Then we check that the mouse is on the selected button. If so, we execute the function associated with the button. In this example button 3 is clicked and convertTo function is executed.
Added new faces for Rebol3 GUI
CheckBox

RadioBox

Horizontal Scroller
Toggle On
Progress









vendredi 12 décembre 2025

Virginia Project: A first paper from R2P2 Lab

https://www.frontiersin.org/journals/pediatrics/articles/10.3389/fped.2025.1636667/full

First, the Virginia software, written with Red language, isolated neonatal anatomy through PyTorch-based PointRend segmentation combined with morphological filtering.

Second, radiometric decoding via ExifTool and ImageMagick extracted pixel-level temperature values mapped to anatomical regions of interest (chest, extremities). Finally, quantitative thermal metrics were derived, including median body surface, temperature and spatial thermal variability (interquartile range).

A key advantage of this automated pipeline is its low operator dependence; once the image is acquired, the entire segmentation and feature extraction process is software-driven, minimizing human interpretation bias.





jeudi 23 octobre 2025

BlurHash with r3

 

What is BlurHash? (from https://uploadcare.com/blog/blurhash-images/ and https://github.com/woltapp/blurhash )

BlurHash is a lightweight way to represent a blurred version of an image that was invented by the Wolt team. It is represented by a short piece of text that when decoded can produce a low quality version of an image which can be shown to the user while the actual image is being loaded.

The idea behind BlurHash is to design a placeholder that is close to the original image but has a smaller size. This makes it possible to send the placeholder to the client side of your application, which reduces the time that the user spends waiting for the page to load.

Oldes wrote an extension for Rebol 3 that makes it very easy to use BlurHash.

See https://github.com/Siskin-framework/Rebol-BlurHash


#!/usr/local/bin/r3
Rebol [
    title: "Rebol/BlurHash test"
]
blurhash: import 'blurhash
cv:         import 'opencv

image: load %../pictures/test1.tiff ;--use your own image
print ["Encoding image of size" as-yellow image/size]
hash: blurhash/encode image
print ["String: " hash]
print ["Decoding hash into image"]
blured: resize blurhash/decode hash 32x32 image/size
;--use OpenCV extension for visualisation
with cv [
print "Source Image"
imshow/name image "Source"
waitkey 0
print "Blured Image"
imshow/name blured "Blured"
waitkey 0
print "Any key to close"
]

Thanks to Oldes!😀




jeudi 2 octobre 2025

SEDFormer

Exciting news! Our paper "SEDformer: Path Signatures and Transformers to Predict Newborns Movement Symmetry" has been accepted at the International Joint Workshop of Artificial Intelligence for Healthcare (HC@AIxIA) and HYbrid Models for Coupling Deductive and Inductive ReAsoning (HYDRA), ECAI 2025.


This research introduces SEDformer, a FEDformer variant that integrates path signatures to enhance newborn movement symmetry prediction - a crucial step toward automated early screening tools for motor development disorders.

Thank you to the entire team for this interdisciplinary collaboration between applied mathematics, AI, and pediatric medicine.

 Rambaud, P., Rimmel, A., Trabelsi, I., Zini, J., Wodecki, A., Motte Signoret, E., Jouen, F., Tomasik, J., Bergounioux, J. (2025). SEDformer: Path Signatures and Transformers to Predict Newborns Movement Symmetry. International Joint Workshop of Artificial Intelligence for Healthcare (HC@AIxIA) and HYbrid Models for Coupling Deductive and Inductive ReAsoning (HYDRA)" ECAI 2025.