View Full Version : QImage-Greyscale-8-bits-pixel
Ivan Labrador
2nd August 2008, 22:45
Hello, I am currently doing my thesis and I am using QT4, I have the following problem: I want to open an image (. Tiff), which has only one dimension, that is, in greyscale (band of a satellite, which is why only in one dimension), and I need to see it as a matrix for porder apply an algorithm, the problem is not how to do to see the values of the pixel in a matrix where the range of these pixel is 0-255, the image is 32-bit, I suppose we must transform to 8. thank you very much.
jacek
2nd August 2008, 23:37
What exactly is the problem? You don't know how to transform an image from 32 bpp to 8 bpp greyscale?
P.S. Please don't start more than one thread on the same topic.
Ivan Labrador
2nd August 2008, 23:50
Hi, I did this:
QString fileName = QFileDialog::getOpenFileName(this, title,QString(),tr("Images (*.tif)"));
if (!fileName.isEmpty())
im_banda1.load(fileName);
QImage ban;
ban=im_banda1.convertToFormat(QImage::Format_Index ed8);
int matrix[100][100];
for(int i=0;i<100;i++){
for(int j=0;j<100;j++){
matrix[i][j]=ban.pixel(i,j);
}
}
and works, the problem is that the pixels are not the same as the original image, ie in the original image I have values 0-255, here too but only 4 wide range, which would seem to lose informaicion.
Ivan Labrador
2nd August 2008, 23:55
sorry, what I'm wrong, the line (*) is well: matrix[i][j]=ban.pixelIndex(i,j);
jacek
3rd August 2008, 00:02
You have converted your image to an indexed format, which means that pixel() doesn't return a color, but an index in the color table (see QImage::color()). If that image is grayscale, you don't have to convert it, just take one of the color components from the pixels:
matrix[i][j] = qRed( im_banda1.pixel( i, j ) );
Ivan Labrador
3rd August 2008, 00:08
Hello friend, now if it worked, really a million thanks, I've saved it, had already stopped 2 days, I will continue. I have another doubt but that I can ask you later. deverdad to thank you very much. God bless you:D
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.