• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
cut strech new Bitmap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cut strech new Bitmap


  • Subject: cut strech new Bitmap
  • From: email@hidden
  • Date: Mon, 03 Dec 2007 05:04:08 -0800

Hello

I am doing some experiments on character recognition.
The idea is to cut out characters from an image, stretch the characters so they fit the input of an neural network.

I have problems to do the cutting shrinking in an efficient way.

The source image (containing all writing) is currently a bitmap.
A rect defines which area shall be cut out (the charater)
Then I create a new bitmap which the source draws the cut out into, with stretching.

+ (NSBitmapImageRep *) createCharacterImage:(NSBitmapImageRep *)image rect:(NSRect)rect {
    NSBitmapImageRep *targetBitmapRep;
    NSRect targetRect = NSMakeRect(0, 0, rect.size.width, rect.size.height);

    NSImage *scaledImage = [[NSImage alloc] initWithSize: targetSize];
    [sourceImage addRepresentation:image];

    [image lockFocus];
    targetBitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:targetRect];
    [image unlockFocus];

    NSGraphicsContext *bitmapGraphicsContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:targetBitmapRep];
    [NSGraphicsContext saveGraphicsState];
    [NSGraphicsContext setCurrentContext:bitmapGraphicsContext];
    [image drawInRect:targetRect fromRect:rect operation:NSCompositeCopy fraction:1.0];
    [image drawInRect:]
    [NSGraphicsContext restoreGraphicsState];

    return targetBitmapRep;
 }

All the hazel of going from bitmap -> to image (used for drawInRect)
Is there another way of creating the new bitmap (targetBitmapRep?

A side note: I only use bitmaps because it is so easy to get all pixel values from x y coordinates, which are then later put into the neural network.

Suggestions are very welcome.
THX
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: cut strech new Bitmap
      • From: Alastair Houghton <email@hidden>
  • Prev by Date: Re: One window, multiple nibs?
  • Next by Date: Re: ImageKit + GC = nogo? (or better... how :D)
  • Previous by thread: Re: One window, multiple nibs?
  • Next by thread: Re: cut strech new Bitmap
  • Index(es):
    • Date
    • Thread