PDA

View Full Version : Doubt in color the image




iphonejudy
Apr 3, 2009, 12:34 AM
hi,


I need to write code for coloring an image.how can i find the orgin of the images.

For example, if i want to color a duck.means , i want to color eyes.so i need to know the orgin of the eyes.

Can anyone give me some idea?



caveman_uk
Apr 3, 2009, 02:24 AM
If I understand you correctly (a big if) then what you're asking is IMO extremely hard - recognising an eye. There are code snippets on the web for doing red-eye correction (such as this one (http://schumaml.gmxhome.de/downloads/gimp/sources/redeye.c)) but what you're asking is much harder. An easier option would be color replacement where the user selects a color to replace and what to replace it with. All you need then are appropriate tolerances on the colors so very similar tones get changed but not dissimilar ones.

iphonejudy
Apr 3, 2009, 03:53 AM
I want to color an image.

For example if it is a man image means,The user wants to give different colors for hair,lips,eyes,shirts and pants know?

So,if the user having his fingers in the shirt means.I need to find the orgin of the shirt and to color the shirt with the color picked by the user.

and if the user placed his fingers in the hair of the image.i need to fill the hair of the image with the color picked by the user.

1)How can i find the orgin of the image(like shirt and pant)

2)Is any useful documents available related to the paint?

PhoneyDeveloper
Apr 3, 2009, 09:26 AM
Google Edge Detection.

iphonejudy
Apr 16, 2009, 12:46 AM
Hi,


I need to develop a paint application in iphone.


I want to paint an image by clicking a color and,if i click in a part of an image ,that part would be filled with the particular color.

Can anyone suggest me the solution?

jmann
Apr 16, 2009, 01:29 AM
Brushes (http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=288230264&mt=8)

iphonejudy
Apr 16, 2009, 01:33 AM
Any documents or sample code related to this,please let me know?

robbieduncan
Apr 16, 2009, 02:47 AM
I'm going to throw you a bone here. I don't know why: I agree with the other posters: you come on here, ask for code without providing any yourself and seem to want everything handed to you on a plate. I'd guess you are about 15, have never had to work a day in your life, have well off parents and are used to getting everything you want, right now. Your sense of entitlement has grown worse and worse since you started posting.

And I disagree that you "just want to get ideas from the senior developeres". You didn't ask for ideas you asked for "the solution" in your first post.

Anyway what you are talking about is performing a flood fill. You can read about many possible algorithms on Wikipedia (http://en.wikipedia.org/wiki/Flood_fill). You will then need to read the Quartz/Core Graphics documentation and decide how to implement this yourself.

iphonejudy
Apr 16, 2009, 04:12 AM
I started my application and i finished the app 25% .

Thanks for all

iphonejudy
Apr 17, 2009, 12:57 AM
Hi i need to color an image.I refered with documents and wrote the below code,


My problem is,i ask 2 fill with red color,but the code fill my image with green color .and if i touch again the image.then the color is change to light green.if again i touch it wil become blank.

Whats the problem in my code?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIColor *greenColor, *blueColor,*redColor;

if(button == @"green" || button ==@"red")
{



NSLog(@"I am Touch");

UITouch *touch = [[event allTouches] anyObject];
if([touch view] == baseImage1)
{
NSLog(@"touch");
//CGPoint location = [touch locationInView:self];
//baseImage.center = location;
image1=baseImage1;
}

if([touch view] == baseImage)
{
NSLog(@"baseImage");
//CGPoint location = [touch locationInView:self];
//baseImage.center = location;
image1=baseImage;
}



if([touch view] == buton1)
{
NSLog(@"buton1");
//CGPoint location = [touch locationInView:self];
//baseImage.center = location;
theColor=greenColor;
}

if([touch view] == buton2)
{
NSLog(@"buton2");
//CGPoint location = [touch locationInView:self];
//baseImage.center = location;
theColor=redColor;
}




NSLog(@"image=%@",image1);


CGImageRef imageRef = self.image1.image.CGImage;
size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
size_t imageWidth = CGImageGetWidth(imageRef);
size_t imageHeight = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);



//CGColorSpaceRef colorSpace ;
CFDataRef dr = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
UInt8* dataPtr = (UInt8*)CFDataGetBytePtr(dr);
int max = bytesPerRow * imageHeight;

for (int i = 0; i < max; i++)
{

if (0 != dataPtr[i + 3])
{


dataPtr[i++]=(UInt8*)redColor;

}
else
i += 3;



}

CGContextRef ref = CGBitmapContextCreate(dataPtr, imageWidth, imageHeight, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);//To set the new image

if (nil == ref)
NSLog(@"Error creating context!");
CGImageRef imageRefNew = CGBitmapContextCreateImage(ref);

UIImage *img = [UIImage imageWithCGImage:imageRefNew];
self.image1.image = img;


CFRelease(imageRefNew);
CFRelease(ref);
CFRelease(colorSpace);
CFRelease(dr);
return self;
}

}

judy

caveman_uk
Apr 17, 2009, 02:22 AM
Well, for starters you haven't assigned a value to redColor, blueColor or greenColor.

iphonejudy
Apr 17, 2009, 03:06 AM
Well, for starters you haven't assigned a value to redColor, blueColor or greenColor.


oh!

then how can i do it in another way? any other solution?

caveman_uk
Apr 17, 2009, 03:54 AM
FFS It's pretty simple really. You need to do -


redColor=[UIColor redColor];


etc.

Looking at the code it's pretty clear to see what you've written and what you've cut and pasted. It isn't going to do what you expect it to do.

iphonejudy
Apr 17, 2009, 05:35 AM
Thanks.its working now

iphonejudy
Apr 20, 2009, 05:14 AM
CGContextRef imageRef = self.image1.image.CGImage;//image1 is a png image
size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
size_t imageWidth = CGImageGetWidth(imageRef);
size_t imageHeight = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = colorSpace = CGColorSpaceCreateDeviceRGB();
CFDataRef dr = CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
UInt8* dataPtr = (UInt8*)CFDataGetBytePtr(dr);
int max = bytesPerRow * imageHeight;


CGContextRef ref = CGBitmapContextCreate(dataPtr, imageWidth, imageHeight, bitsPerComponent, bytesPerRow, colorSpace,kCGImageAlphaNoneSkipLast);


CGContextSetRGBFillColor(ref, 1.0, 0.0, 0.0, 0.0);//to set red color

//I need to fill color of the image

.............


}


I refered the document that i saw CGContextFillRect() is available for fill rectangle,

Is there any function available for fill color for png image?

robbieduncan
Apr 20, 2009, 05:38 AM
I refered the document that i saw CGContextFillRect() is available for fill rectangle,

Is there any function available for fill color for png image?

There is no built-in flood fill function. You have to write it yourself. I have already provided you with a link to a number of potential algorithms for this. If you are unable to turn an algorithm into working code it's time to pay for a professional programmer to do it properly.

iphonejudy
Apr 20, 2009, 05:43 AM
There is no built-in flood fill function. You have to write it yourself. I have already provided you with a link to a number of potential algorithms for this. If you are unable to turn an algorithm into working code it's time to pay for a professional programmer to do it properly.


oh.Thanks

iphonejudy
Apr 20, 2009, 06:37 AM
Can we color a particular pixel ?

robbieduncan
Apr 20, 2009, 06:54 AM
Can we color a particular pixel ?

There is this clearly linked document in the documentation (http://developer.apple.com/iphone/library/qa/qa2007/qa1509.html) that tells you how to get the pixel level data from a CGImage. You should then manipulate that data and set your CGImage to that data once complete. Note the warnings regarding data format etc in the note.

iphonejudy
Apr 20, 2009, 07:07 AM
There is this clearly linked document in the documentation (http://developer.apple.com/iphone/library/qa/qa2007/qa1509.html) that tells you how to get the pixel level data from a CGImage. You should then manipulate that data and set your CGImage to that data once complete. Note the warnings regarding data format etc in the note.


ya ,I saw this document earlier.here they mention how to get pixel,I am asking is there any function available to color a pixel?

robbieduncan
Apr 20, 2009, 07:08 AM
ya ,I saw this document earlier.here they mention how to get pixel,I am asking is there any function available to color a pixel?

Once you have the pixel data you simply need to set the values in the data to represent the colour you want respecting the bits per component, colour ordering and so on. There is no function that I am aware of that will set a single pixel value for you.

iphonejudy
Apr 21, 2009, 02:08 AM
How can we convert grayscale image to color image?(So that i can color red,blue...)

mccannmarc
Apr 21, 2009, 03:31 AM
Do you actually have an imagination? How do you expect us all to know the answer to every question you have when the majority of us have never tried to do what you are doing?

All the solutions that have been suggested to you are either plain common sense or products of peoples imagination and ideas they have come up with based on your questions. It wouldn't kill you to sit and have a think about how to solve something before flooding this forum with question after question, one answer never seems to be enough for you. I hope when you release this app on the AppStore you quote the members of MacRumours as the lead developer!

robbieduncan
Apr 21, 2009, 04:46 AM
How can we convert grayscale image to color image?(So that i can color red,blue...)

The document in my previous post actually has the answer to this in it if you read and understand it.

iphonejudy
Apr 21, 2009, 05:31 AM
I used the code in the documentation,i got the below error in the line


CGContextRef CreateARGBBitmapContext (CGImageRef inImage)

//error: conflicting types for 'CreateARGBBitmapContext'

iphonejudy
Apr 21, 2009, 06:45 AM
its solved

dejo
Apr 21, 2009, 10:36 AM
its solved
How?

Luke Redpath
Apr 21, 2009, 12:00 PM
I feel sorry for any companies shipping off their iphone development to India on the cheap...seems like they're all on here getting others to do their work.

dejo
Apr 21, 2009, 01:36 PM
I feel sorry for any companies shipping off their iphone development to India on the cheap...seems like they're all on here getting others to do their work.
Yeah, and we're giving them the answers for free. Makes it real cheap. It's one thing to ask for the occasional help, especially when helping others back in return. It's another to bombard this forum with loads of question, some of which are pretty basic programming, and then never contribute back to the community. Posters who show a pattern of this I've chosen to no longer assist.

eddietr
Apr 21, 2009, 05:46 PM
Posters who show a pattern of this I've chosen to no longer assist.

That's probably a good plan.

I don't want to pick on any particular country, but I've worked with a few of these outsourcing outfits. Some of them are pretty unscrupulous. They throw projects at developers who have next to no chance of completing them in any reasonable timeframe. Training is basically nonexistent. And if you don't produce, you're out. And forget about collecting your next paltry paycheck.

And the managers of this places wouldn't know a retain count from an orangutan. Nor do they care. "Hey, this fellow programmed an HTML last week, surely he can make an iPhone program for this customer this week."

It's all just "screens", right?

mccannmarc
Apr 21, 2009, 06:01 PM
I don't know why anyone would outsource their software needs to some of these companies! If you ever actually get the software you ask them to produce it is usually of poor quality anyway, having said that I suppose you get what you pay for...

eddietr
Apr 21, 2009, 06:06 PM
I don't know why anyone would outsource their software needs to some of these companies! If you ever actually get the software you ask them to produce it is usually of poor quality anyway, having said that I suppose you get what you pay for...

Well, I'm sure there are good firms (or maybe a good team or two in some firms), but my experience as a customer is you don't save any money in the long run at all.

You end paying for people cutting and pasting whatever random stuff they can find on forums and Google Code or whatever. Maybe some of it works, maybe not. Then you end up 3 months behind schedule and you have to hire proper developers to finish the project anyway (or you've lost enough cash to just drop the idea). Or scream loud enough and a manager will put one of their 10 - 20 actual qualified developers (out of thousands) on your project just long enough to not be sued.

Crazy business, really. But I actually feel sorry for the developers themselves. It's not their fault.

mccannmarc
Apr 21, 2009, 06:14 PM
Well, I'm sure there are good firms (or maybe a good team or two in some firms), but my experience as a customer is you don't save any money in the long run at all.

You end paying for people cutting and pasting whatever random stuff they can find on forums and Google Code or whatever. Maybe some of it works, maybe not. Then you end up 3 months behind schedule and you have to hire proper developers to finish the project anyway (or you've lost enough cash to just drop the idea). Or scream loud enough and a manager will put one of their 10 - 20 actual qualified developers (out of thousands) on your project just long enough to not be sued.

Crazy business, really. But I actually feel sorry for the developers themselves. It's not their fault.

Exactly, not to mention that the chances of your application being future scalable are pretty much zilch. One of my previous employers outsource a lot of their internal software development to India (not that this applies to all software development houses in India, its just the only example I have to draw from) and as a result the majority of the software they have is of inferior quality and barely fit for purpose. As you say the money they save on getting the software developed is more than compensated for by getting portions rewritten and even the time spent by the employees finding ways of avoiding the use of the software etc. They don't learn from this though and are adamant that outsourcing is the future and a key part of their cost reducing incentives.

I just wonder how long it is going to take industries to realize that outsourcing to the poorer countries to (superficially) save a bit of money is usually counter productive in many, many ways.

I also feel sorry for the developers but generally they are very demanding of answers and have no issues with flooding the forum for answers to ridiculous questions. It's very easy to get annoyed with someone when you have helped them with a question and pretty much instantly they ask another question or completely dismiss any answer you have provided them. They are still capable of basic etiquette whether under pressure from managers or not and are in my opinion plain rude

eddietr
Apr 21, 2009, 06:30 PM
They don't learn from this though and are adamant that outsourcing is the future and a key part of their cost reducing incentives.

Well, many times the decision makers on things like that wouldn't know a retain count from an orangutan themselves.

Again, I have no doubt that the actual developers in those countries (or any country) could learn to develop good code given the proper training and education. That's not the issue. The issue is unscrupulous firms who sell thousands of developers when in reality they have dozens.

And customers who hardly know any better. I was forced to outsource twice by investors/boards in companies I used to work for. I'll never do that again.


I also feel sorry for the developers but they are very demanding of answers and have no issues with flooding the forum for answers to ridiculous questions. It's very easy to get annoyed with someone when you have helped them with a question and pretty much instantly they ask another question. They are still capable of basic etiquette whether under pressure from managers or not and are in my opinion plain rude

Some of that is cultural. (I'm Indian, by the way). Some just poor English skills.

And some of that is intense pressure. Like "build this app or you're not paying the rent (or eating for that matter) this month. And I don't care if the requirements are way over your head."

mccannmarc
Apr 21, 2009, 06:41 PM
Its a shame that people have to work under those conditions and even more of a shame how many large corporations take advantage of that for their own gain. Makes you realise how lucky you are really when its put into perspective

iphonejudy
Apr 22, 2009, 01:43 AM
//when touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{ UIColor *theColor1;
UIColor *greenColor,*blackColor,*redColor;

greenColor =[UIColor redColor];
blackColor =[UIColor blackColor];
redColor=[UIColor redColor];

theColor1 =redColor;

image1=baseImage1;

[pictureScreenController colorizeImage:image1.image color:theColor1];

}


+ (UIImage *)colorizeImage:(UIImage *)baseImages color:(UIColor *)theColor {

NSLog(@"I am colorizeImage");
UIGraphicsBeginImageContext(baseImages.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();
CGRect area = CGRectMake(0, 0, baseImages.size.width, baseImages.size.height);

CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height);

CGContextSaveGState(ctx);
CGContextClipToMask(ctx, area, baseImages.CGImage);

[theColor set]; //the color to set


CGContextFillRect(ctx, area);//fill color



CGContextDrawImage(ctx, area, baseImages.CGImage);//draw image

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;// return image


}


[theColor set] contains

redColor : Color=UIDeviceRGBColorSpace 1 0 0 1//same values set for green and red
greenColor : Color=UIDeviceRGBColorSpace 1 0 0 1
blueColor: Color=UIDeviceRGBColorSpace 0 0 1 1
blackColor : Color = UIDeviceRGBColorSpace 0 1


But the color is not fill in the image CGContextFillRect(ctx, area);//fill color

What i did wrong in the code?

iphonejudy
Apr 22, 2009, 01:50 AM
problem solved.I didnt return the correct image.

dejo
Apr 22, 2009, 10:52 AM
problem solved.I didnt return the correct image.
...and the disappointment continues...