Page 2 of 6 FirstFirst 123456 LastLast
Results 11 to 20 of 60

Thread: [Award Winner] Bitmapped Images - The technical side of things explained.

  1. #11
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,244
    Blog Entries
    8

    Post Resampling

    This means changing the image resolution or the number of pixels. The idea is to preserve the original image in the best possible way. The techniques involved are split depending on whether going up or down.

    Down means taking a big image and making it smaller. Your going to lose information and what we would like to do is lose the least amount. Although all paint packages have the ability to do it a few key presses and one pass they all seem to be universally useless at it. If your going from 1000 to 800 then the best way is to upsample from 1000 to a large multiple of 800 like 3200, or 4000 and then blur and downsample to a 1/4 or 1/5. If changing in much larger ratios like 1000 to 173 or something like that then find a nice multiple of 173 larger than 1000 - i.e. 1730 and upsample to that first then blur 10 pixels into one and then down sample by 1/10th. Many people say - oh always use Bicubic or always use Lanczos but I disagree and I will show the results here with bicubic from 1000 down to 173. Maybe you disagree. Mathematically a sinc resample should be the best possible but I dont think the paint apps implement the full sinc and the windowing makes the resample less effective as more scaling is applied.

    Up means taking a small image and making it bigger and here the paint apps seem to do it as well as can be expected so just picking the right algorithm is all thats needed. Again here, people often say that Bicubic or Lanczos is the best and for most images I would agree but there are exceptions. For general work including maps and photos I think its true and below is a sample sheet.

    Where the situation changes is with noise and ringing and with small scales. If you are resampling from 997 to 1000 or something very very close to what you want then I would use a pixel/point/nearest neighbor based resample because for about 99% of that image the pixels will not change. Below is a set of lines resampled up very slightly.

    You will have to save and zoom up this last image to see whats happening. My monitor makes all three pretty much gray.
    Attached Images Attached Images
    Last edited by Redrobes; 07-27-2008 at 11:28 AM.

  2. #12
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,244
    Blog Entries
    8

    Post Resampling and its effect on color

    We can clearly see in many cases of resampling that some pixels are made from the average of several others. This is particularly true in upsample using cubic weighting. We have also said earlier that averaging two pixels in any color space can cause some odd results so this section is some gotchas to look out for and what to do about them. This is an area that I am least familiar with since I only use RGB and dont bother trying to fix these but its worth knowing anyway.

    We noted that a blend from red to blue in RGB color space would give deep mauve - ok but look at this. This is an up sample of some colors which have some issues. Some of the corners here are pure green but the other is red & blue (magenta). When we average these two colors together the red & blue from one image drop halfway and the green from the other drops halfway. End result - all halfway to give mid gray ! Now its worth noting that for resample types that dont allow blends like the nearest neighbor then you dont get the issue. Also, it turns out that if you apply a gamma adjustment to the image, resample with a cubic and the apply and reverse gamma adjustment then the problem gets fixed. I havent fully convinced myself why this is true but I am assured it is.
    Attached Images Attached Images
    Last edited by Redrobes; 07-27-2008 at 10:57 AM.

  3. #13
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,244
    Blog Entries
    8

    Post Upsampling curvy black and white stuff

    Reserved space - but this one came up recently too.
    EDIT -- actually this comes up a lot and again today so here we go again... how to resample up just B&W stuff.

    First, upsample anyway you like in factors of double (200%) in stages until one more is less than double (say 1.7).
    For each stage double the size of the image which makes it pixellated - a nearest neighbor / pixel resize is fine.
    Next, blur it - preferably using gaussian blur. The amount of blur radius can be experimented with but about a factor of 3 pixels or so.
    Then use contrast to clamp it back to being B&W again. Actually I use about 95% or so not 100% but its up to you. Dont brighten it or darken it when you do it, just up the contrast.
    Keep doing this in stages until the last stage is <200% in which case you might want slightly less blur than usual but not by much.
    Here is the results. Everything is cool except for where there is an acute internal angle where it tends to start filling in depending on the amount of blur used. So less blur helps, but more blur is better to get rid of pixellation. You have to experiment with it.
    Attached Images Attached Images
    Last edited by Redrobes; 09-29-2008 at 05:52 PM.

  4. #14
    Community Leader jfrazierjr's Avatar
    Join Date
    Oct 2007
    Location
    Apex, NC USA
    Posts
    3,057

    Post

    *Head 'sploid*


    Thanks for spending ALL the time to explain all this. Unfortunatly, my head just can't comprehend 90% of it, so I stopped reading at half of the first article. Sooooo I gave you a rating and rep, cause even if it won't help me, I am 100% sure someone will read it and get some help from the work.

    Joe
    My Finished Maps
    Works in Progress(or abandoned tests)
    My Tutorials:
    Explanation of Layer Masks in GIMP
    How to create ISO Mountains in GIMP/PS using the Smudge tool
    ----------------------------------------------------------
    Unless otherwise stated by me in the post, all work is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.

  5. #15
    Community Leader Facebook Connected Ascension's Avatar
    Join Date
    Jun 2008
    Location
    St. Charles, Missouri, United States
    Posts
    8,392

    Post

    At least I now comprehend why the anomalies happen even though I need much much more practice in fixing them, as explained here, to be really comfortable with actually doing them and fully understanding them. Thanks Red, very informative.

  6. #16

    Post

    Awesome! Thank you so much, Redrobes.

    Do you happen to be able to explain in general terms how the different resampling algorithms work? I would love to be able to choose one based on an understanding of what it's going to do rather than trying to rely on an imprecise rule of thumb.

    It's so nice to have a programmer around who knows how to talk down to my level!
    Bryan Ray, visual effects artist
    http://www.bryanray.name

  7. #17

    Post

    This turorial is Great, and answers many questions I have had wrt imaging terms. Thank you for posting it.

    While I am still something of a dummy (at least a newbie) when it comes to imaging software in general, I am less of a dummy when it comes to electronics.

    Quote Originally Posted by Redrobes View Post
    it turns out that if you apply a gamma adjustment to the image, resample with a cubic and the apply and reverse gamma adjustment then the problem gets fixed. I havent fully convinced myself why this is true but I am assured it is.
    Since I was also curious about gamma correction, I looked up gamma correction in search engine and found following document:
    http://www.cgsd.com/papers/gamma_intro.html


    Based on this, I think that gamma correction does nothing to the image data itself, it is simply a setting for when image is displayed on monitor. So if you first halve the original value, and later double it for a separate image, the new image ends up with the original value, and at no point is the image data altered by changing the gamma setting.

    I'm not sure if this helps to understand the issue or not. I would need to be a bit more familiar with sampling methods.

    Edit: Warning! The attempt at insight contained in this post, is most likely either dead wrong or completely irrelevant to this topic. Every line after I thank Red Robes for posting this tutorial, should probably be disregarded.
    Last edited by yu gnomi; 07-29-2008 at 04:16 AM.

  8. #18
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,244
    Blog Entries
    8

    Post

    Quote Originally Posted by Midgardsormr View Post
    Do you happen to be able to explain in general terms how the different resampling algorithms work?
    Ok, first let me say that all of these resamples work separately in X and Y so think of it doing a stretch in width followed by a stretch in height and the same process is applied in each case. So we can talk about just a stretch in one direction. Often the PC will do both at once for performance reasons tho.

    Well the first is the simplest and quickest and you have seen that it often produces the worst results but can be the best in certain circumstances and that is the point sampled. Often called nearest neighbor or sometimes a pixel resize.

    Say your going up from 100 pixels to 140 pixel image - thats a multiply by 1.4. What the PC does is loop over the 140 pixels and divide the pixel number by 1.4 and then look up the nearest pixel in the original image and use that. What that means also is that occasionally it will hit the same original pixel a few times duplicating the result and you can see that in the 997 to 1000 stretch example. Occasionally theres a double black or double white line. When you use this stretch the output is always blocky in appearance.

    Linear resampling takes the same approach and runs over the 140 pixels and divides the position by 1.4 so that it will give a value of say 86.3. What the PC does is look at pixels 86 and 87 and take 70% of 86 and 30% of 87 and adds them up. Its a straight up linear interpolation.

    For cubic its harder to describe but it does the same loop and get the same 86.3 value. Now it looks at 4 pixels. 85,86,87, and 88. It applies a cubic weighting function over the top of the four and adds them up. The cubic curve in the middle is like an S shape so that its a smoother blend at the known source pixels.

    Lanczos is a windowed sinc function. That means its a sinc which is just sin(x) / x but restricted to a window of either 5 or 7 pixels (either side) depending on whether your using Lanczos5 or Lanczos7. It just so happens (lots of math) that a sinc function is the perfect function to use for resampling but that a sinc function goes on and on and never ends so they suppress it inside a smaller window. Anyway I think Lanczos5 will look at 9 pixels, multiply with a windowed sinc function and then add them all up.

    Its called bilinear, and bicubic because the function is applied in two directions at once so whats actually happening is that a patch of pixels are being processed at once.

    There are more types but they are all much the same style. Look at a patch of source pixels and interpolate a new destination pixel based on that patch. You can get better image results the more you know about what was going on in the location around the source.

    Edit -- just fact checking, it seems the 5 or 7 is not either side but the total amount of points so either 2 or 3 either side.
    Last edited by Redrobes; 07-28-2008 at 10:25 AM.

  9. #19
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,244
    Blog Entries
    8

    Post

    Quote Originally Posted by yu gnomi View Post
    I think that gamma correction does nothing to the image data itself, it is simply a setting for when image is displayed on monitor.
    You can apply color correction and gamma adjustment globally at the video card stage and this would affect everything and not affect the pixel values but to do that color fix up with resampling, you have to apply a gamma function to the pixels first and then apply the stretch and then apply the inverse gamma function. Although in the example provided the first gamma function does nothing because all of the colors start saturated if you tried to do it to a photo then you need that first gamma adjustment if your going to apply an inverse one later. Your right in that gamma adjustments are used to compensate for the effects of monitors - esp CRT type. Why this process works to fix this problem I am not sure. I am not sure if a different compensation curve would also work.

  10. #20

    Post

    http://www.ononesoftware.com/product...e_fractals.php

    This is a link to program that does an incredible job at up scaling images

    I can not tell you how much I wish I had this program at my current job

    I am sick of getting 15 kb .jpg logo files

Page 2 of 6 FirstFirst 123456 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •