I'm also searching for a way to colorize the image...
But Actually what I need is to add a TONE to a grayscale image ...
I'll surf the web and Will post here result ...
I'm also searching for a way to colorize the image...
But Actually what I need is to add a TONE to a grayscale image ...
I'll surf the web and Will post here result ...
Oh i see... i dont know the right word for that either..
sepia i think is similar to colorize... im working on colorize...
pretty mindboggling for me with all the RGBs manipulation.
seems im gonna have to do it myself.
I found some samples in the net, but all are using matrix to do Hue.
I am wondering if anybody done it with just normal equations which
modify the pixels one by one?
Hello rahul, the codes all assumes the image has ARGB format.
ie
index = alpha channel
index+1 = red channel
index+2 = green channel
index+3 = blue channel.
this normally is true for PNG images. But, in case of other formats, you need to cater for it.
my advise is pre-process your loaded images into png first (and scale it down a bit).
HTH.
Thanks a lot Rocotilos, Image that i was using is in BGR format. so i changed code accordingly. Now when i tried to use another image(i.e. bmp file), code doesn't work properly.
Can you tell me how to convert any image of any format to Png(ARGB) format?
UIGraphicsBeginImageContext(rect.size);
[oldImage drawInRect:rect]; // scales image to rect
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
rect.size should be your image size (or whatever size you want it to be-its good to resize to smaller size should the user loads up a 3MP or 5MP photos/images) oldimage is original image, from whatever format. and newImage is the image in ABGR.
And, sorry, this code actually returns ABGR all the time, which is good too. my mistake on prev post (for saying convert it to ARGB)..
UIGraphicsBeginImageContext(rect.size);
[oldImage drawInRect:rect]; // scales image to rect
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
rect.size should be your image size (or whatever size you want it to be-its good to resize to smaller size should the user loads up a 3MP or 5MP photos/images) oldimage is original image, from whatever format. and newImage is the image in ABGR.
And, sorry, this code actually returns ABGR all the time, which is good too. my mistake on prev post (for saying convert it to ARGB)..
HTH
Great... Thanks for sharing the information. It helped me a lot.
I found some samples in the net, but all are using matrix to do Hue.
I am wondering if anybody done it with just normal equations which
modify the pixels one by one?
Yea.. the Hue i figured it out, but.. er.. i got an app doing that so cannot be shared. lol.
to blur is easy, you just set pixel 1 to be the average of pixel 1 and pixel 2. there are many types of blurring, but averaging is simplest and it works.
to sharpen, you need to enhance the difference between the 2 pixels if the difference is big. i could share but.. er. also have an app doing that too.. hehe sorry. i can only summarise what it does.
Yea.. the Hue i figured it out, but.. er.. i got an app doing that so cannot be shared. lol.
to blur is easy, you just set pixel 1 to be the average of pixel 1 and pixel 2. there are many types of blurring, but averaging is simplest and it works.
to sharpen, you need to enhance the difference between the 2 pixels if the difference is big. i could share but.. er. also have an app doing that too.. hehe sorry. i can only summarise what it does.
You sell an image processing app but yet you don't know how to change the hue of an image? Are you just cutting and pasting random code?
You sell an image processing app but yet you don't know how to change the hue of an image? Are you just cutting and pasting random code?
If u read properly, I said I KNOW. But just not willing to share the code at the moment. And I don't get you replying a thread like this. Would you like to share your code?
bit of a newb and just playing around and am looking for some help if you don't mind?
Basically i understand everything thats been posted etc, quick question though: how would i go about accessing the rgb values for a particular X and Y co-ordinate?
i found: 4*((imageWidth*round(Y))+round(X))
but i can't seem to get it to work, adjusting the X co-ordinate works fine but adjusting the Y co-ordinate value seems to pick a pixel that is nowhere near where i wanted?
am i along the right lines with the above formula or am i well off?
//Load in the image we want to analyse
UIImage *c = [UIImage imageNamed:@"test.jpg"];
//Convert image to format we can look at
CGImageRef inImage = CGImageRetain(c.CGImage);
CGContextRef ctx;
//Get the pixel data from the image
CFDataRef m_DataRef;
m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
// Byte tmpByte;
int length = CFDataGetLength(m_DataRef);
//NSLog(@"len %d", length);
int bytesPerPixel = 4;
int imageWidth = CGImageGetWidth(inImage);
int imageHeight = CGImageGetHeight(inImage);
int x = 25;
int y = 25;
int offset = 4*((imageWidth*round(Y))+round(X))
NSLog(@"offset:%i", offset);
m_PixelBuf[offset+1] = 255;
m_PixelBuf[offset+2] = 1;
m_PixelBuf[offset+3] = 1;
//Create an image from the pixel data
ctx = CGBitmapContextCreate(m_PixelBuf,
CGImageGetWidth( inImage ),
CGImageGetHeight( inImage ),
8,
CGImageGetBytesPerRow( inImage ),
CGImageGetColorSpace( inImage ),
kCGImageAlphaPremultipliedFirst );
CGImageRef imageRef = CGBitmapContextCreateImage (ctx);
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
CGContextRelease(ctx);
//Set the UIImage to the new image data
testPic2.image = rawImage;
thats a rough outline of the code im using, picture im testing on is a 50px by 50px pixel just as a test yet trying to get x,y of 25,25 doesn't yield the pixel in the dead center of the image
Just made this. The above also works but, seems too many calculation in the loop making the process lag a bit.
This one, is better for adjusting contrast:
contrast is a UISlider with value 0-200, default 100.
Code:
int aRed = data[index+1];
int aGreen = data[index+2];
int aBlue = data[index+3];
aRed = (((aRed-128)*contrast.value )/100) + 128;
if (aRed < 0) aRed = 0; if (aRed>255) aRed=255;
data[index+1] = aRed;
aGreen = (((aGreen-128)*contrast.value )/100) + 128;
if (aGreen < 0) aGreen = 0; if (aGreen>255) aGreen=255;
data[index+2] = aGreen;
aBlue = (((aBlue-128)*contrast.value )/100) + 128;
if (aBlue < 0) aBlue = 0; if (aBlue>255) aBlue=255;
data[index+3] = aBlue;
Hi again Rocotilos,
In my app I would like to add a contrast (and then a better brightness control too) slider to modify an UIImageView.
I take the photo from the library or from the camera, then I convert it to GRAY SCALE and then, as you suggested in this post, I've re-processed the images to obtain an ABGR simply with this lines:
And since now, on simulator, all is ok except for the fact that I don't know if the gray image in the screen has now been converted to ABGR. I've done it because I would like to use you code to change constrast so...
I'm actually tryng use your code by this way:
The slider is between 0-200 with 100 initial value.
The result simply don't work. Just slide a little and the human face (example) disappear and the foto turns gray!
I've tryed to manually set the int value in contrast method to 10, 50, 110... all the same result: picture turns gray.
I'm really not a master of image pixel manipulation, I still have to read and learn but I'm doing some test now and now I don't know what I'm doing wrong! Probably is there a stupid beginner error in the contrast code (created from me with your code mixed with another code found for the brightness mabe in the wrong way!)!
Hello DVDKite, sorry I didnt notice you were asking on this thread.
I saw a small mistake on your code
-(void)contrastint)value{
value is supposed to be CGFloat (or float) type, because that is what a UISlider's value format is in. And pls be sure that the slider's min and max value is set to 0.0f and 200.0f respectively.
You can check your image color format this way:
1. temporary comment out all that contrast code.
2. just put data[index+1]=255; data[index+2]=0; data[index+3]=0; data[index]=255;
if it turns red, then u know index+1 is RED, therefore chances are format is ARGB.
if it turns blue, the u know index+1 is BLUE< therefore chances are format is ABGR
etc.. test it this way..
You must make sure all images you loaded into your app has the same format.
As for me, i use that code post #37 above. all images are gone thru that function, therefore
it returns the image in the same color format.
ALSO, probably it is better to put a typecast for the data.