PDA

View Full Version : How to avoid correcpted images



swarupa
17th March 2016, 06:10
Hi all ,
I am displaying images of size 352 x 240 and in those some are corrupted images. Now , i am trying to avoid corrupted images then what i need to do .

I have the following code

if (image.pixel(image.width() - 1, image.height() - 1) == 4286611584 &&
image.pixel(image.width() / 2, image.height() - 1) == 4286611584 &&
image.pixel(0, image.height() - 1) == 4286611584) {
val = 0; // invalid color : 4286611584 (default gray jpg)
if (val == 0) {

ui->label->setPixmap(QPixmap::fromImage(image));
}
} else {
val = 1;

if (val == 1) {

ui->label->setPixmap(QPixmap::fromImage(image));
}
}

In this they gave

image.pixel(image.width()-1,image.height()-1 ) = 4286611584
image.pixel(image.width()/2,image.height()-1 ) = 4286611584
image.pixel(0,image.height()-1 ) = 4286611584

but i am getting different values like
image.pixel(image.width()-1,image.height()-1 ) = 4278255360
image.pixel(image.width()/2,image.height()-1 ) = 4278900992
image.pixel(0,image.height()-1 ) = 4279949312

How those values are coming based on pixel or something else .

How to calculate the image size in pixels?

wysota
17th March 2016, 08:56
How those values are coming based on pixel or something else .
Based on pixel colour.


How to calculate the image size in pixels?
See QImage::size() or simply width()*height()

ChrisW67
17th March 2016, 21:54
JPEG images undergo lossy compression. There is no guarantee that an original pixel with colour RGB(128,128,128) will appear unmodified after being transferred to and then from JPEG format. This is especially an issue at image edges and low contrast flat areas. Open your "corrupt" image in a photo editor and closely inspect the lower right corner at high zoom.


If the image files are actually corrupt then you cannot rely on the image size or pixel values anyway. Does isNull() return false? Does valid() return true for the pixels concerned?