Problem with streaked vertical lines

Or how about a higher resolution photo degraded by an oft saved jpeg. This problem only occurs in Jpegs saved multiple times and then cropped and they may be saved at a low quality setting. This is to be expected with jpegs, but I know what you are going to say. Why did it not happen before ios7.
 
Or how about a higher resolution photo degraded by an oft saved jpeg. This problem only occurs in Jpegs saved multiple times and then cropped and they may be saved at a low quality setting. This is to be expected with jpegs, but I know what you are going to say. Why did it not happen before ios7.

Exactly. It didn't happen and doesn't happen pre-iOS7.

Also, we're talking as well about a one time conversion to black and white in an app, then sending it to camera roll, not app stacking. Why does it turn purple? That question really needs to be answered.
 
@Tai Shimizu @Stackables
Just to add something, we had started a similar discussion in iPhoneArt time ago, then decided to write something in the Apple Forum as well where you can find here the discussion. At the end of that discussion I added a link to a bug reported in Open radar that involve UIImageJPEGRepresentation, that you can read here, and that might be interesting for you to know. I don't know if this is another method used in the process, or one of the possibility you can use for saving the pictures on the camera roll.

David was kind enough to confirm that Monokrom doesn't have this problem and I also don't see the problem if I keep opening/saving my own output.

I will say that I don't use that UIImageJPEGRepresentation call when I save my jpeg rendition of the image.

-- non developers stop reading here for your own sanity :) --

I use the ALAssetLibrary call writeImageToSavedPhotosAlbum:metadata:completionBlock: to write my jpegs. I am passing in a UIImage (via CGImage) that I created using a bitmap gc and the metadata is the original metadata sourced from the image the user selected with the image picker (I just change the orientation entry).
 
I just tried the same test you folks tried with a well known and much loved app and I got the same results - a gradual shift towards magenta each time the image went through the Load/Save cycle. I just pulled the file over to my Mac for closer examination.
 
Hi guys—sorry to be late to the party (it'd be really great, @Venomator, if there was a way to get an e-mail alert when tagged...).

It's not surprising that a simple load/save will change the file when you look at what is typically happening to it (although there is a way around this for app developers).

In theory, a JPEG image should not need to be recompressed if it hasn't been changed (and even, in some circumstances, if it has, in a way—such as an orientation change—that only affects the metadata and not the image data.

In practice, what generally happens is this (at a technical level, it's different with loading an image from Camera Roll, and loading it from an app's private space or via Open In..., but the end result is the same):

  1. The image data is loaded into memory as one of Apple's internal image formats (typically CGImage or UIImage). This involves a conversion of the image data from compressed (and encoded and...) Y'CbCr data to uncompressed RGBA.
  2. Even if the image is unchanged, when it is saved to a new location it's the CGImage or UIImage that is saved as a JPEG, which involves the re-conversion of the image data from uncompressed RGBA to compressed (and encoded and...) Y'CbCr
So there are two key changes to the image data. Its seems most likely to me that the algorithm for either the compression or the expansion of the Y'CbCr data has a flaw, which is causing the shift towards purple. The banding, too, seem likely to be the result of flawed handling of the 8x8 pixel blocks in which JPEG data is held. If I had to go for one or the other I'd guess the problem was at the point where the JPEG is converted to RGB rather than at the other end—just a hunch.

The way around this for developers, at least with unaltered images, is to flag whether the image has been edited and, if not, to ignore the CGImage or UIImage they've created and get the data directly from the source file with, say,
Code:
NSDatadataWithContentsOfURL:
and write it straight out to the destination (using
Code:
writeImageDataToSavedPhotosAlbum:metadata:completionBlock:
for Camera Roll). For simple orientation changes or other metadata changes the metadata alone can be extracted, tweaked and saved with the unchanged image data using this technique.

With images that have been altered, it's trickier.

The only real answer is to use non-lossy formats until final output has been created—which is what imaging pros normally do anyway on the desktop. JPEG is an excellent format for final output—it's a lousy workflow tool if you value image integrity and you will get quality problems surfacing after repeated edits, even without (apparent) OS-level bugs.

Of the formats natively supported by iOS, both PNG and TIFF are lossless. I much prefer TIFF for photographs because it has excellent metadata support—PNG doesn't—and writing TIFFs (even compressed ones) is much faster than writing PNGs. (And compressed TIFFs are generally smaller, because PNG's compression algorithm wasn't really designed for handling continuous tone efficiently.)
  • If an app saves and re-loads temporary files during the editing process I think it's extremely important that it uses a lossless format—there could be dozens of saves that a user isn't aware have taken place!
As far as format support is concerned, it may be helpful to know that image editors can open any image that's been saved to Camera Roll, whatever the format (the conversion to uncompressed RGB is handled by iOS) but each supported output format must be manually added by the developer—JPEG is a doodle, JPEG with configurable compression is pretty simple, PNG is a bit harder and TIFF is a bit harder still (but still pretty straightforward). Equally, each format the the app supports with Open In... has to be manually specified by the developer. This is why there are so many apparent disconnects between different formats an app may seem to support in different places.
 
So if I understand you start with a camera app that takes a tiff photo and go to an editor like Filterstorm and then save the final edited image in tiff if you think more editing might happen or save in Jpeg if it's final. The open in stuff still confuses me. If you have a tiff and you open in in FS I think you should be okay.
 
So if I understand you start with a camera app that takes a tiff photo and go to an editor like Filterstorm and then save the final edited image in tiff if you think more editing might happen or save in Jpeg if it's final. The open in stuff still confuses me. If you have a tiff and you open in in FS I think you should be okay.


@Mike Hardaker Thank you Mike for this detailed explanation that help us to better understand how things work and most of all trying to figure out how to solve this very annoying purple problem. Some apps have this purple problem at the very first save without having to test the same save very times. Do you think Apple is aware about this or it would be the case to make them read this discussion?


@Mikeraboy Michael, the problem, as written before, is that we don't know how an app handles the conversion. You might think the passing a Tiff file into another app that save Tiff files would be ok, but the reality is that it depends on how apps convert files. That app could convert into jpg the file when you use "open in", or the next app could convert in jpg when importing a file from the camera roll, and then the output could be Tiff with a reconversion of the file again. Each area is a developer decision but these kind of things are not generally explained to anyone, so for each app we should run tests to be sure at 100%.
It might be obvious to think that if an app "saves" in Tiff, it handles Tiff also as import, or also as "open in..." but this is not sure.
 
So if I understand you start with a camera app that takes a tiff photo and go to an editor like Filterstorm and then save the final edited image in tiff if you think more editing might happen or save in Jpeg if it's final. The open in stuff still confuses me. If you have a tiff and you open in in FS I think you should be okay.
Yes. It's the only way to stop "generation loss". Clearly this is not always possible, but keeping JPEG saves to a minimum is key if you're aiming for the highest possible quality. If you're only creating images for sharing online at low quality then all this is pretty irrelevant!
 
Any devs who want to see just how messed up the internal JPEG processing has become might enjoy compiling this:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker
                    didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

    float compLevel = 1.0;
    UIImage *tintedImage = originalImage;
    for (int i=0; i<10; i++) {
            NSData *data = UIImageJPEGRepresentation(tintedImage, compLevel);
            tintedImage = [UIImage imageWithData:data];
    }

    [picker dismissViewControllerAnimated:YES completion:nil];
}
And then compare tintedImage with originalImage...
magenta.jpg

Note: originalImage is genuinely monochrome; it's the loop that causes the color shift.

(Edit: I should note that we don't use any code that looks remotely like this in our apps... ;-)]
 
Last edited:
Mauro, thanks for taking the time to conduct this test.

I find the results very surprising! I'm not sure what's happening here. We'll investigate the matter further tomorrow, but in the meantime could you answer the following questions?

1 - Do you see this only in photos shot with your iPhone 5s?
2 - Did you see the same results in other images that you tested?
3 - How did you convert to black and white?
4 - What are the pixel dimensions of the image?
5 - Did you shoot the image in square format or did you crop it afterwards?
6 - Do you see the same results in colored images?

Thanks
Sam

Hi, Sam!
I did another test with Photofusion, trying to open/save the image you posted here, without crop or BW conversion.
Here is the result...

===========================
TEST - iPhone5S (IOS 7.0.5)
App: PHOTOFUSION
Process: simply open and save, without editing, no crop, no BW conversion (10 times)
===========================

Original image
foto 1.JPG

foto 2.PNG


Final image (after 10 times)
foto 3.JPG

foto 5.PNG


Degradation, step by step
foto 4.PNG



Waiting for your reply, thank you in advance!
:)
Mauro
 
Any devs who want to see just how messed up the internal JPEG processing has become might enjoy compiling this:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker
                    didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage *originalImage = info[UIImagePickerControllerOriginalImage];

    float compLevel = 1.0;
    UIImage *tintedImage = originalImage;
    for (int i=0; i<10; i++) {
            NSData *data = UIImageJPEGRepresentation(tintedImage, compLevel);
            tintedImage = [UIImage imageWithData:data];
    }

    [picker dismissViewControllerAnimated:YES completion:nil];
}
And then compare tintedImage with originalImage...
View attachment 51086
Note: originalImage is genuinely monochrome; it's the loop that causes the color shift.

(Edit: I should note that we don't use any code that looks remotely like this in our apps... ;-)]

Great clarification, Mike!!
Uhm, it seems like "tintedImage" has ONLY a purplish tone compares with "originalImage" but NO visible quality degradation, right?
 
Uhm, it seems like "tintedImage" has ONLY a purplish tone compares with "originalImage" but NO visible quality degradation, right?
This is a screen grab—I didn't bother saving the image and then looking at it full size. Also, the quality is set to 100%. With quality—compLevel— set to 80% and the code modified to add:
Code:
UIImageWriteToSavedPhotosAlbum(tintedImage, nil, nil, nil);
after the for() loop (again, not code we use...), here are 100% details from the original and final images, complete with pretty substantial degradation—zoom in to see more clearly, but there's heavy banding that's 8px wide:
magenta_banding.jpg
 
Hi, Sam!
I did another test with Photofusion, trying to open/save the image you posted here, without crop or BW conversion.
Here is the result...

===========================
TEST - iPhone5S (IOS 7.0.5)
App: PHOTOFUSION
Process: simply open and save, without editing, no crop, no BW conversion (10 times)
===========================

Original image
View attachment 51087
View attachment 51089

Final image (after 10 times)
View attachment 51088
View attachment 51090

Degradation, step by step
View attachment 51091


Waiting for your reply, thank you in advance!
:)
Mauro

Hi Mauro, I'm very surprised that your results are very different from mine and those of Mike, which leads me to suspect that the image you extracted from this thread has deteriorated in quality. To be on the safe side, please use an image of your own that has not been resized or processed in any way. Also, if possible, send it to us on [email protected] so we can test it simultaneously and get to the bottom of the issue. Don't forget to set the compression slider to 1 in settings.

Sam
 
This is a screen grab—I didn't bother saving the image and then looking at it full size. Also, the quality is set to 100%. With quality—compLevel— set to 80% and the code modified to add:
Code:
UIImageWriteToSavedPhotosAlbum(tintedImage, nil, nil, nil);
after the for() loop (again, not code we use...), here are 100% details from the original and final images, complete with pretty substantial degradation—zoom in to see more clearly, but there's heavy banding that's 8px wide:
View attachment 51092
Thank you, Mike. You're right, if I zoom-in the degradation is (not drastic but) visible :-/
 
Hi Mauro, I'm very surprised that your results are very different from mine and those of Mike, which leads me to suspect that the image you extracted from this thread has deteriorated in quality. To be on the safe side, please use an image of your own that has not been resized or processed in any way. Also, if possible, send it to us on [email protected] so we can test it simultaneously and get to the bottom of the issue. Don't forget to set the compression slider to 1 in settings.

Sam
Hi, Sam, I did another test with Photofusion with a new image taken with native camera app at full resolution (as usual, without crop or BW conversion).
Here is the result...

===========================
TEST - iPhone5S (IOS 7.0.5)
App: PHOTOFUSION
Image: taken with native camera app at full resolution
Process: simply open and save (JPEG 100% quality, setting compression slider to 1), without editing, no crop (10 times)
===========================

Original image
foto 1.JPG

foto 2.PNG


The final image (after 10 times)
foto 3.JPG

foto 4.PNG


Crop of original and final image:
foto 2.PNG
foto 1.PNG


I just sent you the original image via email.

I'm waiting for the result of your test, Sam!
Mauro
 
Back
Top Bottom