cut strech new Bitmap
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