RGB and Adjusting Brightness

17 views
Skip to first unread message

da4thrza

unread,
Aug 27, 2009, 3:48:04 PM8/27/09
to simple-iphone-image-processing
Hi,

Im very new to objective c and the iphone sdk, so please excuse me if
this is a stupid question. I tried using your sample project and
noticed that you have code in place to convert it to grayscale. I went
into the image constructor and say where you are using

CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceGray();

I tried changing this to CGColorSpaceRef
colorSpace=CGColorSpaceCreateDeviceRGB(); but that didnt work and
simply changed the image to all black.

Could you please tell me how to keep the image in full color?

Also, i would like to adjust the brightness of the image. Is that done
by using the normalise function? If so, is there a way to tell it how
much to brighten an image?

Thanks in advance for your help!

Chris Greening

unread,
Aug 27, 2009, 4:36:28 PM8/27/09
to simple-iphone-i...@googlegroups.com
try this:

typedef struct _rgbPixel {
uint8_t a;
uint8_t b;
uint8_t g;
uint8_t r;
} RGBPixel;

RGBPixel *getRawValuesFromImage(UIImage *srcImage, int width, int height) {
RGBPixel *rgbImage=(RGBPixel *) malloc(width*height*sizeof(RGBPixel));
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
CGContextRef context=CGBitmapContextCreate(rgbImage,  width, height, 8, width*4, colorSpace, kCGBitmapByteOrder32Little|kCGImageAlphaNoneSkipLast);
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGContextSetShouldAntialias(context, NO);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), [srcImage CGImage]);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return rgbImage;
}


The image normalisation just stretches the range of values so that they are in the rand 0-255. If you want to brighten an image then you need to increase the value of each pixel (but don't forget that the maximum pixel value is 255).

Marcelo Roque

unread,
Aug 27, 2009, 4:39:21 PM8/27/09
to simple-iphone-i...@googlegroups.com
Hey Chris, may I ask you something too? Don't know if you got my message, but I was wondering if you could post on that "extractConnectedRegion" and "findLargestStructure" sample code. I can't find a way to make that work properly with an "Cannyed"  image.

Thanks

2009/8/27 Chris Greening <cmgre...@gmail.com>

Chris Greening

unread,
Aug 27, 2009, 4:57:12 PM8/27/09
to simple-iphone-i...@googlegroups.com
Hi Marcelo,

Sorry, yes I got your message, I'm just catching up on the emails now.

The problem you might be having is that the canny algorithm is marking an EDGE as 0 and NOEDGE as 255.

The extract connection region and find largest structure are looking for pixels of 255 - so you are currently extracting the NOEDGE pixels instead of the EDGE pixels.

If you invert the canny image (set anything that is 0 to 255 and anything that is 255 to 0) you should get it to work.

Cheers
Chris.

Marcelo Roque

unread,
Aug 27, 2009, 5:18:36 PM8/27/09
to simple-iphone-i...@googlegroups.com
Hm, Chris, what would be the "std::vector<ImagePoint> *maxPoints"?

Marcelo

Chris Greening

unread,
Aug 27, 2009, 5:38:13 PM8/27/09
to simple-iphone-image-processing
I'm not sure I understand the question.

But I think if you invert the canny image and then feed it into the
findLargestStructure you should end up with a vector of points that
are the edge points.

da4thrza

unread,
Aug 27, 2009, 5:55:01 PM8/27/09
to simple-iphone-image-processing
Thanks a million Chris! Ill try this out on my Mac as soon as i get
home
> > Thanks in advance for your help!- Hide quoted text -
>
> - Show quoted text -

Marcelo Roque

unread,
Aug 27, 2009, 5:58:29 PM8/27/09
to simple-iphone-i...@googlegroups.com
I'm actually doing this...

" edges.image->findLargestStructure(edges.image.m_imageData);" but I am getting an error that goes:  "Confused by earlier error, bailing out."

Any idea?

2009/8/27 Chris Greening <cmgre...@googlemail.com>

Chris Greening

unread,
Aug 27, 2009, 6:16:15 PM8/27/09
to simple-iphone-i...@googlegroups.com
You should be doing something like this:

std::vector<ImagePoint> points;
edges.image->findLargestStructure(&points);

This will give a vector containing all the points in the image that make up the largest structure.

Cheers
Chris.

Marcelo Roque

unread,
Aug 27, 2009, 6:21:09 PM8/27/09
to simple-iphone-i...@googlegroups.com
Oh, think I understood. Thanks Chris!

Marcelo

2009/8/27 Chris Greening <cmgre...@gmail.com>

da4thrza

unread,
Aug 27, 2009, 6:38:13 PM8/27/09
to simple-iphone-image-processing
Hey Chris,

Sorry if i should already know the answer to this, but i have a
question about your response. The method you posted will return a
RGBPixel, but looking at the code you posted in your sample project,
you first make a call to createImage which in turn calls the
constructor to image (the one that was converting to greyscale).
Should i just create a new constructor for Image and take the code
within the getRawValuesFromImage method and paste it in there? If
thats the case, i will obviosuly remove the return rgbimage; line from
there, but do i also need to make teh call to initYptrs();?

Thanks again!

On 27 Aug, 13:36, Chris Greening <cmgreen...@gmail.com> wrote:

Chris Greening

unread,
Aug 27, 2009, 6:47:37 PM8/27/09
to simple-iphone-i...@googlegroups.com
Hi,

The code in the image class will only work with greyscale images so
you won't be able to plug in the the code I've given you and make it
work.

I'm afraid you'll have to write your own function to do full colour
image processing.

To access the pixels use:

RGBPixels *rgbData=getRawValuesFromImage....

Then to access a pixel at X and Y:

rgbData[x+y*width].r
rgbData[x+y*width].g
rgbData[x+y*width].b

Hope that helps. There's not much more I can tell you.

da4thrza

unread,
Aug 27, 2009, 6:50:33 PM8/27/09
to simple-iphone-image-processing
Got it... thanks again for all your help!
> >> - Show quoted text -- Hide quoted text -

da4thrza

unread,
Aug 28, 2009, 2:12:24 PM8/28/09
to simple-iphone-image-processing
Hey Chris,

Just wanted to thank you again... i got it all working last night.
Thanks for your help and willingness to share!

Reza

On 27 Aug, 15:47, Chris Greening <cmgreen...@gmail.com> wrote:
> >> - Show quoted text -- Hide quoted text -

Franky Orson

unread,
Oct 17, 2009, 2:06:06 PM10/17/09
to simple-iphone-image-processing
Hi Reza,

Any chance you would be willing to share your changes or submit them
to the project?

Thanks

--Frank
Reply all
Reply to author
Forward
0 new messages