It is currently Fri Oct 20, 2017 3:46 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pixel interpolation?
PostPosted: Thu Dec 29, 2016 6:17 am 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3064
Location: Brazil
I use a RGB palette. Any other way of interpolating the pixels than arithmetic mean in each component?


Top
 Profile  
 
 Post subject: Re: Pixel interpolation?
PostPosted: Thu Dec 29, 2016 7:50 am 
Offline

Joined: Sun Mar 19, 2006 9:44 pm
Posts: 915
Location: Japan
There are many ways. You could calculate the path from one colour to the other using quadratic formulas, or splines. Also, use HSV, CMYK, HSL, etc. colour spaces when interpolating. Each colour space will give different intermediate colours, each more or less artistically suited to what you want.

[Edit] This page looks like an obvious good place to start: https://en.wikipedia.org/wiki/HSL_and_HSV

_________________
http://www.chrismcovell.com


Top
 Profile  
 
 Post subject: Re: Pixel interpolation?
PostPosted: Thu Dec 29, 2016 4:55 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
You need to convert from SRGB (your usual 8-bit RGB format) into Linear RGB, then do componentwise interpolation there, then convert back to SRGB.

Image

Here's a common example image that gets ruined with typical SRGB algorithms. If you downscale by 50% by adding 4 pixels then dividing by 4, you get solid gray. Just try resizing this down to 50% size in a common image editor, you'll see it happen.
But in the Linear RGB color space, you get correct results.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
 Post subject: Re: Pixel interpolation?
PostPosted: Fri Dec 30, 2016 9:33 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19104
Location: NE Indiana, USA (NTSC)
If you're trying to do this in a pixel shader, and doing the full conversion between linear and sRGB in real time is hard, you can use approximate sRGB as gamma 2. To convert to linear power, square it (power = value*value), and then to convert back, take the square root (value = power * rsqrt(power)). This is fast on GPUs because they have a dedicated instruction for reciprocal square root (rsqrt(x) = x-1/2) for use in lighting and other calculations that use unit normal vectors. If you want to prototype your algorithm in a well-known image editor before you write code, the equivalent operation in GIMP or Photoshop is applying Levels with gamma 0.5, doing your blurring or scaling, and then applying Levels with gamma 2.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: 93143 and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group