Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-16-2010, 12:02 PM   #51 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 1
arubinst is on a distinguished road
Question

Hello everyone, I'll start by saying that this thread is awesome! Very, very useful.

I'm sorry to bring it back to life, but I have a problem that maybe some of you might help me solve.

I'm thresholding an image by using some code obtained from the examples shown here. I started by using a fixed threshold value and then moved to a slider. Both cases worked as expected. The slider gives a very nice effect as the changes reflect immediately when the slider is moved, because the image is very small.

I'm now trying to implement a kind of "automatic" thresholding inside a loop. What I would like to do is apply the thresholding routine for a varying threshold value and be able to reflect the changes on the image as the threshold value changes.

The problem is that you cannot see any progress. Changes are only updated after the loop finishes executing.

I have tried setNeedsDisplay on the UIImageView and on the parent view. I'm also delaying the loop with a [NSThread sleepForTimeInterval:xx] but the result is always the same. I cannot see the image changing. I only obtain the final version after the loop.

Any ideas?

Thanks!
arubinst is offline   Reply With Quote
Old 10-04-2010, 07:43 PM   #52 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 1
shizam is on a distinguished road
Default

Thank you all,
This thread has been immensely helpful and I have several matrix transforms working but I have one big problem:

On a 5MP image on an iPhone4G they take upwards of 10-11 seconds to process the full image (by iterating over each pixel as illustrated in this thread). Anybody have a way to speed this up, is it better to do work on PNG vs JPG data, is there a way to hardware accelerate it?

Thanks
shizam is offline   Reply With Quote
Old 11-14-2010, 02:49 AM   #53 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 3
RednebMas is on a distinguished road
Default

I know that this is a really old thread but I have been looking at it a lot and if anyone else out there is I would like to help. It also fixes the problems that I have been having with the previous code. For example, in the previous code on this topic, if you made no changes to the image it would have a different output.

There is a much easier way to edit each pixel individually. Here is a function that returns the image without red. Code is from here Can I edit the pixels of the UIImage's property CGImage - Stack Overflow

Code:
- (UIImage *)imageProcess:(UIImage *)image
{
    // load image
    CGImageRef imageRef = image.CGImage;
    NSData *data        = (NSData *) CGDataProviderCopyData(CGImageGetDataProvider(imageRef));
    char *pixels        = (char *)[data bytes];
	
    // manipulate the individual pixels
    for(int i = 0; i < [data length]; i += 4)
    {
        int r = i;
        int g = i+1;
        int b = i+2;
        int a = i+3;
		
        pixels[r]   = 0;
        pixels[g]   = pixels[g];
        pixels[b]   = pixels[b];
        pixels[a]   = pixels[a];
    }
	
    // create a new image from the modified pixel data
    size_t width                    = CGImageGetWidth(imageRef);
    size_t height                   = CGImageGetHeight(imageRef);
    size_t bitsPerComponent         = CGImageGetBitsPerComponent(imageRef);
    size_t bitsPerPixel             = CGImageGetBitsPerPixel(imageRef);
    size_t bytesPerRow              = CGImageGetBytesPerRow(imageRef);
	
    CGColorSpaceRef colorspace      = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo         = CGImageGetBitmapInfo(imageRef);
    CGDataProviderRef provider      = CGDataProviderCreateWithData(NULL, pixels, [data length], NULL);
	
    CGImageRef newImageRef = CGImageCreate (
											width,
											height,
											bitsPerComponent,
											bitsPerPixel,
											bytesPerRow,
											colorspace,
											bitmapInfo,
											provider,
											NULL,
											false,
											kCGRenderingIntentDefault
											);
    // the modified image
    UIImage *newImage   = [UIImage imageWithCGImage:newImageRef];
	
    // cleanup
    free(pixels);
    CGImageRelease(imageRef);
    CGColorSpaceRelease(colorspace);
    CGDataProviderRelease(provider);
    CGImageRelease(newImageRef);
	
	return newImage;
}
RednebMas is offline   Reply With Quote
Old 11-15-2010, 02:00 AM   #54 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Quote:
Originally Posted by shizam View Post
Thank you all,
This thread has been immensely helpful and I have several matrix transforms working but I have one big problem:

On a 5MP image on an iPhone4G they take upwards of 10-11 seconds to process the full image (by iterating over each pixel as illustrated in this thread). Anybody have a way to speed this up, is it better to do work on PNG vs JPG data, is there a way to hardware accelerate it?

Thanks
As far as I know, there is no way to speed it up. Speed pretty much depends on CPU speed of the hardware. If you want, you can try using image editing with openGL, but i doubt it will improve speed.. because if you have big chunk of pizza, no matter how u split the chunk, if you have 10 people eating it, the total time to be completely eaten is going to be same.
rocotilos is offline   Reply With Quote
Old 12-06-2010, 08:57 AM   #55 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 2
mkotliarov is on a distinguished road
Default Image binarization

Hello arubinst, I'm trying to do an image binarization app. I've read a lot of documents from Internet about image binarization, thresholding and so on. Can you share some code to get the idea of a good thresholding algorithm? I need to do a binarization of image with text, but not doing OCR. Thanx a lot.
mkotliarov is offline   Reply With Quote
Old 01-22-2011, 11:21 AM   #56 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 104
Sakura is on a distinguished road
Default

Seems like a helpful thread about editing image data.
Sakura is offline   Reply With Quote
Old 03-03-2011, 05:26 PM   #57 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 50
JavaWizKid is on a distinguished road
Question

Very useful hread. How do I set the

Code:
m_PixelBuf[index + 1] = 255 - m_PixelBuf[index + 1]; 
		m_PixelBuf[index + 2] = 255 - m_PixelBuf[index + 2]; 
		m_PixelBuf[index + 3] = 255 - m_PixelBuf[index + 3];
To display the image as it is originally intended?
__________________
Discover new apps through art! Sound weird? Check it out! BigAppAd!
Follow me on Twitter!
JavaWizKid is offline   Reply With Quote
Old 04-11-2011, 05:58 PM   #58 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 176
Rifts is on a distinguished road
Default

can someone please upload an example app with source code?
Rifts is offline   Reply With Quote
Old 07-27-2011, 03:52 AM   #59 (permalink)
Registered Member
 
Join Date: May 2011
Posts: 5
ajin2605 is on a distinguished road
Default Change brightness and contrast with multitouches

Hi all,
Thanks for useful topic!
I'd like to know that did anybody here change brightness and contrast of DICOM images with touch moves event?!

If YES, would you please post the code here ?!

Thanks and regards,
DKien
ajin2605 is offline   Reply With Quote
Old 01-19-2012, 08:36 AM   #60 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default Everything has changed with iOS 5

This whole topic was turned upside down with the release of iOS 5. Apple finally added Core image filters in iOS 5.

Core Image (CI) filters use OpenGL shader code under the covers to do transformations on images EXTREMELY fast. Many of the filters are fast enough to operate on a video from the camera and display onto the screen in real time.

I haven't tackled using CI filters on video yet, but it's fairly straightforward to use a filter on a still image.

One gotcha is that CI filters take an object called a CIImage as input, and return a CIImage as output.

There's a UIImage method in iOS 5, initWithCIImage, that's supposed to take a CIImage as input and create a UIImage. It doesn't work. it returns a UIImage that has the correct bounds, but lacks the backing CGImage containing the pixels. I wasted a bunch of time yesterday tracking down this bug, and have submitted a radar bug. Please, everybody reading this, go write your own variation on this bug. Apple uses the number of bug reports they get to set their priorities on bug fixes.

Below is a sample method I wrote yesterday that takes a UIImage as input, and returns an adjusted UIImage as output. It uses the CIColorControls method to adjust the brightness of an image. It would be trivial to change it to use lots of different Core Image filters.

The "if (TRUE)" bit enables the work-around code that makes it possible to convert a CIIImage to a CGImage, and then to a UIImage. If you change "if (TRUE)" to "if (FALSE)", the code tries to use the Apple iOS 5 method, which doesn't work.

I got the work-around from Erica Sadun's new "iOS 5 Developer's Cookbook" from Addison Wesley. (http://www.amazon.com/iOS-Developers...6983449&sr=8-1)

This book is truly outstanding. It is chock-full of useful information, and includes a decent introduction to Objective C, Xcode, the portal, etc. Where it really shines is tons of working examples of techniques you can use to solve real-world problems in your applications.

Erica is has a PHD in computer science, and her knowledge of iOS is both deep and wide. Plus, she writes well.

I think it's the best fit for intermediate to advanced programmers. If you've got experience with development on another platform, and are learning iOS, it should be perfect.

I can't say enough good things about this book.

Unfortunately, there was a problem with the first printing, and it had to be scrapped. The new version is due out in 10 days. I have one of the misprints, and even with the printing problems, I would gladly pay twice the price for it.


Code:
- (UIImage *) changeImageBrightness: (UIImage *) anImage
                             amount: (CGFloat) amount;
{
  UIImage *adjustedUIImage;
  CIImage *adjustedCIImage;
  CGImageRef adjustedCGImage;
  CGImageRef inputCGImage = anImage.CGImage;
  CIImage *inputCIImage = [CIImage imageWithCGImage: inputCGImage];
  
  CIFilter *colorFilter = [CIFilter filterWithName: @"CIColorControls"
                                     keysAndValues: 
                           @"inputBrightness",  [NSNumber numberWithFloat: amount],
                           @"inputImage",       inputCIImage,
                           nil];
  adjustedCIImage = [colorFilter valueForKey: kCIOutputImageKey];
  
  if (TRUE)
  {
    //This works
    adjustedCGImage = [[CIContext contextWithOptions:nil] createCGImage: adjustedCIImage fromRect:inputCIImage.extent];
    adjustedUIImage = [UIImage imageWithCGImage: adjustedCGImage];
  }
  else
  {
    //This doesn't work
    adjustedUIImage = [UIImage imageWithCIImage: adjustedCIImage];
    adjustedCGImage = adjustedUIImage.CGImage;
  }
  return adjustedUIImage; 
}
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
bitmap, effects, filter, image proccessing, uiimage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
5 members and 321 guests
Anwerbl, guusleijsten, HowEver, LEARN2MAKE, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,879
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:38 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0