Anand
Anand

Reputation: 1973

Image Filtering

I have an application that requires some work on image filters, so I just started working on filters and I achieved few filters like Black & white, Hud, moss,brightness,contrast etc.

Here are few filters that I am facing problem to achieve

  1. Nostalgia
  2. Vintage
  3. Old

Original Image

enter image description here

Nostalgia

enter image description here

vintage

enter image description here

old

enter image description here

If anyone can guide me on the right direction it would be great.

Thanks in advance.

Upvotes: 1

Views: 993

Answers (3)

nilx
nilx

Reputation: 1

It seems that you need to determine the parameters of a RGB transformation. If you already have a tool to produce the "vintage", "old" and "nostalgia" effects, then you can process a sample image containing all the 256^3 RGB colors (like this one), then observe, for example color channel by color channel to start simply, how the pixel values are modified. This may be enough to deduce the RGB transform function. And "old" will require a dark shadow on the border.

Upvotes: 0

Krishnabhadra
Krishnabhadra

Reputation: 34265

This thread is very informative about image filtering in iphone...

EDIT

This what I have done to make an image vintage (Vintage image requirement in my case was slightly different..It didn't have shades on the edges)

//first increase contrast a bit...
float contrastValue             =   1.45;
CGImageRef originalImage        =   [myImage CGImage];
CGColorSpaceRef colorSpace      =   CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext      =   CGBitmapContextCreate(NULL,CGImageGetWidth(originalImage),CGImageGetHeight(originalImage),8,CGImageGetWidth(originalImage)*4,colorSpace,kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(bitmapContext, CGRectMake(0, 0, CGBitmapContextGetWidth(bitmapContext), CGBitmapContextGetHeight(bitmapContext)), originalImage);
UInt8* data                     =   CGBitmapContextGetData(bitmapContext);
int numComponents               =   4;
int bytesInContext              =   CGBitmapContextGetHeight(bitmapContext) * CGBitmapContextGetBytesPerRow(bitmapContext);
double redIn, greenIn, blueIn;

for (int i = 0; i < bytesInContext; i += numComponents) {
    redIn                       =   (double)data[i]/255.0;
    greenIn                     =   (double)data[i+1]/255.0;
    blueIn                      =   (double)data[i+2]/255.0;
    
    redIn                       -=  0.5;
    redIn                       *=  contrastValue;
    redIn                       +=  0.5;
    redIn                       *=  255.0;
    if (redIn < 0) {
        redIn                   =   0;
    }
    if (redIn > 255) {
        redIn                   =   255;
    }
    
    greenIn                     -=  0.5;
    greenIn                     *=  contrastValue;
    greenIn                     +=  0.5;
    greenIn                     *=  255.0;
    if (greenIn < 0) {
        greenIn                 =   0;
    }
    if (greenIn > 255) {
        greenIn                 =   255;
    }
    
    
    blueIn                      -=  0.5;
    blueIn                      *=  contrastValue;
    blueIn                      +=  0.5;
    blueIn                      *=  255.0;
    if (blueIn < 0) {
        blueIn                  =   0;
    }
    if (blueIn > 255) {
        blueIn                  =   255;
    }
    data[i]                     =   (redIn);
    data[i+1]                   =   (greenIn);
    data[i+2]                   =   (blueIn);
}
CGImageRef outImage             =   CGBitmapContextCreateImage(bitmapContext);
myImage                         =   [UIImage imageWithCGImage:outImage];
CGImageRelease(outImage);

//Then blend it with a yellowish color
UIGraphicsBeginImageContext(myImage.size);
CGContextRef ctx                =   UIGraphicsGetCurrentContext();
CGRect area                     =   CGRectMake(0, 0, myImage.size.width, myImage.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSaveGState(ctx);
CGContextClipToMask(ctx, area, myImage.CGImage);
UIColor *color                  =   [UIColor colorWithRed:248.0/255.0 green:254.0/255.0 blue:186.0/255.0 alpha:1.0]; //[UIColor colorWithRed:248.0/255.0 green:254.0/255.0 blue:186.0/255.0 alpha:1.0]
[color set];
CGContextFillRect(ctx, area);
CGContextRestoreGState(ctx);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextDrawImage(ctx, area, myImage.CGImage);
myImage                         =   UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIGraphicsBeginImageContext(myImage.size);
ctx                             =   UIGraphicsGetCurrentContext();
 area                           =   CGRectMake(0, 0, myImage.size.width, myImage.size.height);
CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);
CGContextSaveGState(ctx);
CGContextClipToMask(ctx, area, myImage.CGImage);
color                           =   [UIColor colorWithRed:27.0/255.0 green:50.0/255.0 blue:224.0/255.0 alpha:0.2]; //[UIColor colorWithRed:248.0/255.0 green:254.0/255.0 blue:186.0/255.0 alpha:1.0]
[color set];
CGContextFillRect(ctx, area);
CGContextRestoreGState(ctx);
CGContextSetBlendMode(ctx, kCGBlendModeLighten);
CGContextDrawImage(ctx, area, myImage.CGImage);
processedImage                  =   UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

This might not work for you as is..Please play with this for your own requirement..Copied from memory, errors possible..

Upvotes: 3

Artur Ozierański
Artur Ozierański

Reputation: 1177

at first check out Core Image documentation. Core image arrived with iOS 5.0 and is powerful image processing api.

Also you can use Quartz to draw image and over layer with different blending options (CGContextSetBlendMode) to achieve some nice effects.

If this techniques are not sufficient you can try changing color values pixel by pixel. Try this url, maybe you find something for you.

Upvotes: 0

Related Questions