Upscaling photos (JPG) and maintaining quality!

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
theonlysandman
Posts: 8
Joined: 2013-12-06T07:47:13-07:00
Authentication code: 6789

Upscaling photos (JPG) and maintaining quality!

Post by theonlysandman »

Hi all,

After a day and a half of reading, testing, trying I am turning to the community for some help.
I am stumped, thought I was getting close but at this point I am just guessing. And it seems this has been solved many times before.

PROBLEM: trying to increase a JPG file from 320x240 to 640x480 an maintain the quality.

The last query I tried was this:

convert sample.jpg -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 15,50% -filter Lanczos -define filter:blur=.9264075766146068 -distort resize 200% -sigmoidal-contrast 15,50% -colorspace sRGB after.jpg

Here are links to the before and the expected after:
http://theonlysandman.ca/imagemagick/before.jpg
http://theonlysandman.ca/imagemagick/after.jpg

Version: ImageMagick 6.8.7-8 Q16 x64
OS: Windows 8 (will be run on Linux as well)

Can anyone help with the correct syntax?

At first I was trying to learn this stuff, now I would just be happy to have a command I can run!

Thanks and talk soon,
Sandy

PS: The main article I have been basing my research off is:
viewtopic.php?f=22&t=21435
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Upscaling photos (JPG) and maintaining quality!

Post by snibgo »

I can't give you better advise than you'll find in those image processing threads. But I will say I think your expectations are unrealistic. Your large image contains detail in areas that have no detail in the small version, eg the house wall to the right of the satellite dish. This detail would have to be "invented" by a very intelligent program.

If you finish up with an unsharp mask, the result will appear slightly sharper.
snibgo's IM pages: im.snibgo.com
theonlysandman
Posts: 8
Joined: 2013-12-06T07:47:13-07:00
Authentication code: 6789

Re: Upscaling photos (JPG) and maintaining quality!

Post by theonlysandman »

Snibgo: Thanks for the feedback. I will try the unsharp mask and see how it goes.

That said, I am 95% sure (but maybe less so now) the before.jpg was used to produce the after.jpg.

Is there a 'very intelligent program' that can do this kind of scaling up? Beside imagemagick...

Once I test unsharp, I will let you know.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Upscaling photos (JPG) and maintaining quality!

Post by Bonzo »

LizardTech's Genuine Fractals ( owned by onOne now ) used to be the program to use for image enlarging and while looking for the name I came across this on the About.com website:
Stair Interpolation
Some folks have discovered that you can get better results when upsampling by increasing the image size in several small increments rather than one extreme step. This technique is referred to as stair interpolation. One advantage to using stair interpolation is that it will work on 16-bit mode images and it requires no additional software other than a standard photo editor, such as Photoshop. The concept of stair interpolation is simple: rather than using the image size command to go directly from 100% to 400%, you would use the image size command and only increase, say, 110%. Then you would repeat the command as many times as it takes to get to the size you need. Obviously, this can be tedious if your software does not have some automation capability.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Upscaling photos (JPG) and maintaining quality!

Post by snibgo »

I think Genuine Fractals could have "invented" some of the fine detail, such as around the edges of the buildings and vegetation. But I'm almost 100% sure that it couldn't do the wall to the right of the satellite dish. This almost convinces me the "before" was made from the "after".

Where did the images come from?
snibgo's IM pages: im.snibgo.com
theonlysandman
Posts: 8
Joined: 2013-12-06T07:47:13-07:00
Authentication code: 6789

Re: Upscaling photos (JPG) and maintaining quality!

Post by theonlysandman »

Snibgo: interesting idea...currently the photos are coming from a real agent via a feed.
We have been told the restrictions are 320x240 maximum but the the 'after.jpg' is 640x480!

So, we assume the after.jpg must have come from come from the 320x240 image.

Unsharpen is helping a bit but the red garage door is still causing issues...

So close but yet so far....

I will check out the Genuine Fractals stuff... thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling photos (JPG) and maintaining quality!

Post by fmw42 »

If you want a sharper result without the unsharp masking use -filter Catrom
theonlysandman
Posts: 8
Joined: 2013-12-06T07:47:13-07:00
Authentication code: 6789

Re: Upscaling photos (JPG) and maintaining quality!

Post by theonlysandman »

fww42: tried the filter Catrom and it acutally seemed to reduce the quality.
convert before.jpg -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 15,50% -filter Catrom -define filter:blur=.9264075766146068 -distort resize 110% -sigmoidal-contrast 15,50% -colorspace sRGB after-catrom.jpg

bonzo: The interative approach seemed a bit better but still not great. Once we get it tweaked, then adding that might help. Thanks!

One new thing of interest, when doing identify on the objects I noticed this in the after.jpg (640x480) that is NOT in the before.
Profiles:
Profile-icc: 3144 bytes
Description: sRGB IEC61966-2.1
Manufacturer: IEC http://www.iec.ch
Model: IEC 61966-2.1 Default RGB colour space - sRGB
Copyright: Copyright (c) 1998 Hewlett-Packard Company
Does that tell you guys anything?

Also, the red door in the photo seems to show the most problems. Any ideas why that is?
Would love any more feedback...

Also, I am not looking to hire someone to help as well. Posted on elance and odesk.... just about to post here as well!



I posted a job on elance and odesk; going to post one here as well. At this point, I am guessing so time to pay the experts for some education!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling photos (JPG) and maintaining quality!

Post by fmw42 »

convert before.jpg -set colorspace sRGB -colorspace RGB +sigmoidal-contrast 15,50% -filter Catrom -define filter:blur=.9264075766146068 -distort resize 110% -sigmoidal-contrast 15,50% -colorspace sRGB after-catrom.jpg
try


convert before.jpg -filter Catrom -distort resize 110% after-catrom.jpg

or

convert before.jpg -filter Catrom -resize 110% after-catrom.jpg
theonlysandman
Posts: 8
Joined: 2013-12-06T07:47:13-07:00
Authentication code: 6789

Re: Upscaling photos (JPG) and maintaining quality!

Post by theonlysandman »

Fred,

Unfortunately, neither of those command worked well...in fact, at 110% the quality fell almost as much as I cuold get at 200% with longer queries.

Here are the afters:
http://theonlysandman.ca/imagemagick/after-catrom.jpg

http://theonlysandman.ca/imagemagick/af ... resize.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Upscaling photos (JPG) and maintaining quality!

Post by fmw42 »

How do you measure quality? Subjective or Objective? If the latter, what measure do you use? There are lots of issues that need to be dealt with. Many compete. For example: blurriness, moire, aliasing, stairstepping, sharpness, ringing. One method may be better for reducing one and do worse on another. I know of no universally best technique. It is also image dependent. Natural scenes vs high contrast or drawings.

I presume you have reviewed Nicholas Robidoux's page at http://www.imagemagick.org/Usage/filter/nicolas/

Personally I prefer sharpness over other issues. That is why I suggested Catrom. But each person has his/her own goals when resizing.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Upscaling photos (JPG) and maintaining quality!

Post by glennrp »

I agree with others who thought that "after.jpg" was not made from "before.jpg".
I tried making the smaller image out of the larger one, with

Code: Select all

convert after.jpg -resize 50% new-before.jpg 
and the resulting 320x240
image (new-before.jpg) is very similar (29189 versus 29729 bytes in filesize) and appearance
to the 640x480 one. So I think both of them were made from a larger original, in two different
sizes, using the same software. By the way, I see the Microsoft ICC profile in both of them, and both have
"quality = 90".
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Upscaling photos (JPG) and maintaining quality!

Post by NicolasRobidoux »

TTBOMK, the only type method that could produce results resembling what you show as before/after is one that uses a training set on downsampled (and JPEG compressed) versions of "mint" images and basically construct the "inverse filter" by matching input patches to "mint" ones. Methods like http://www.nec.com/en/global/techrep/jo ... 120217.pdf or those discussed in http://forum.doom9.org/showthread.php?p ... ost1650281 where they are compared to a variant of ImageMagick's -filter LanczosSharp -distort Resize with a nonlinear "ripple suppression" filter.
This being said, I don't think that the state of the art would give consistent results like the one you show without a highly targeted training set.
And I would not be surprised if "before" and "after" were reversed somehow :)
-----
As far as ImageMagick goes, I'd have a look at http://www.imagemagick.org/Usage/filter ... upsampling as Fred Weinhaus suggested. This document does not quite reflect my current opinion RE: best practices, but is pretty close. The fact that you are enlarging by exactly a factor of 2 changes the game somewhat. So does the fact that your "before" image is fairly low quality (as far as JPEG compression goes).
Last edited by NicolasRobidoux on 2013-12-07T07:28:25-07:00, edited 2 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Upscaling photos (JPG) and maintaining quality!

Post by NicolasRobidoux »

Additional links that suggest that, at least for video content, "-filter LanczosSharp -distort Resize" is reasonably good when combined with ripple suppression: http://forum.doom9.org/showthread.php?p ... ost1650208 and http://forum.doom9.org/showthread.php?p ... ost1654751.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Upscaling photos (JPG) and maintaining quality!

Post by NicolasRobidoux »

@Bonzo: Most people will find the results of stair interpolation disappointing compared to the best ImageMagick methods.
Stair interpolation is basically a way of mitigating the shortcomings of "primitive" upsampling methods.
Last edited by NicolasRobidoux on 2013-12-07T07:38:47-07:00, edited 1 time in total.
Post Reply