Reputation: 71
I have to compare two 2d vectors (vect_2d_a
and vect_2d_b
) and as a result I will construct a 2d vector/2d array (vect_compare_result
) comprising the difference in value of vect_2d_a
and vect_2d_b
.
Basically I can simply print the vect_compare_result
and view it, but I would like to see it as a figure with simple boxes indicating the difference value in pixels (like colorbar in matlab).
Is it possible to display a simple 2d vector into a figure using Qimg
or something?
Priya
Upvotes: 0
Views: 1475
Reputation: 3271
Assuming that size of your vector is n x n
:
QImage image(n, n, QImage::Format_RGB32);
QRgb value;
for (int i=0;i<N;++i) {
for (int j=0;j<N;++j) {
value = getColor(vect_compare_result); //a function that returns color based on value
image.setPixel(i, j, value);
}
}
If you want your pixels to be bigger (like one box is 5x5 real pixels):
int box_size = 5;
QImage image(n * box_size, n * box_size, QImage::Format_RGB32);
QRgb value;
for (int i=0;i<N;++i) {
for (int j=0;j<N;++j) {
value = getColor(vect_compare_result);
for (int k=0;k<box_size;++k)
for (int l=0;l<box_size;++l)
image.setPixel(i+k, j+l, value);
}
}
Upvotes: 1