Skip to content

Mirror image to align QImage and OpenGL texture coordinates#151

Merged
alxvth merged 1 commit into
masterfrom
feature/Fix2dColorMapMirror
Mar 3, 2026
Merged

Mirror image to align QImage and OpenGL texture coordinates#151
alxvth merged 1 commit into
masterfrom
feature/Fix2dColorMapMirror

Conversation

@alxvth
Copy link
Copy Markdown
Contributor

@alxvth alxvth commented Mar 3, 2026

In ImageProp::setColorMapImage we use

texture.reset(new QOpenGLTexture(colorMapImage));

Qt's docs on QOpenGLTexture suggest:

QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).flipped());

Note that the QImage is flipped vertically to account for the fact that OpenGL and QImage use opposite directions for the y axis. Another option would be to transform your texture coordinates.

Currently this yields a different re-coloring in the ImageViewer vs the Scatterplot for the same data:
image

The data here is a 2D image where each pixel value is its coordinates, i.e. at (x: 0, y: 0) the value is (1: 0, 2: 0) and at (x: 25, y: 50) the value is (1: 25, 2: 50)
image

When mirroring the texture image we get consistent behavior:

image

In the scatterplot we use Texture2D::loadFromImage from the core (Texture.h) via the PointRenderer.
There we just use (QRgb*)image.bits() to point to the color values instead of converting a QImage to QOpenGLTexture, which appears to behave differently.

@alxvth alxvth requested a review from ThomasKroes March 3, 2026 13:40
@alxvth
Copy link
Copy Markdown
Contributor Author

alxvth commented Mar 3, 2026

Just for sake of reproducibility, the code to generate the test images:

import numpy as np
from PIL import Image

size = 100

# Image 1: x-gradient (columns 0-99, same across all rows)
# Flip vertically so (0,0) is bottom-left
x_array = np.tile(np.arange(size, dtype=np.float32), (size, 1))
x_array = np.flipud(x_array)

# Image 2: y-gradient (rows 0-99, constant across each row)
# y goes 0 (bottom) to 99 (top)
y_values = np.arange(size, dtype=np.float32)
y_array = np.tile(y_values, (size, 1)).T
y_array = np.flipud(y_array)

Image.fromarray(x_array, mode='F').save('./1.tiff')
Image.fromarray(y_array, mode='F').save('./0.tiff')

@alxvth alxvth merged commit 136eb40 into master Mar 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants