I'm looking for the most efficient way to offset the content of an image as if it was a torus surface. In other words, I want the parts that move outside the canvas to come back on the other side (e.g. left to right and up to down).
Is there a dedicated argument for that?
As Mark Setchell has pointed out, -roll +X+Y is the correct method in ImageMagick. In the following, I roll the image to the right by half of its width.
Input:
convert mandril3.jpg -roll +128+0 mandril3_roll.jpg
Result:
Related
I was wondering what would be the best way to trim the "canvas" of an UIImage (pretty much like any image editor allows out there)
Now, the previous example is not a single UIImage. It's actually 2 UIViews. So clipping the superview against the blue box would do the trick, but I guess I am looking into the best possible way to do this. Given that there could be several blue boxes in the "canvas".
Is there a faster way than going through every pixel?
Thanks!
Thinking about it algorithmically, I would say no. You need to find the pixel that extends furthest to the left, right, top and bottom. Unless you look at every pixel from each direction you could miss non-transparent pixels.
You could speed things up if you figure out how to map your image into memory and then index into memory directly rather than using a high level function that fetches pixels. I would suggest searching from the top down (which would be sequential memory accesses) until you find a non-clear pixel. Then search from the end of the image backwards, which would give you the bottom-most pixel.
You would then want to limit your search from each side to only look starting at the first non-transparent pixel from the top and ending at the last non-transparent pixel on the bottom.
For anything other than a very large image this should take a fraction of a second.
Ok, I was being dumb. The union of the subviews is all I really needed, so its just a simple loop over the subviews and doing a CGRect union against their frames.
I'm developing an OCR app that reads the digits and copy them to clipboard automatically instead of manually typing...
I'm using (TesseractOCR) ... But before recognizing and in the image manipulating I'm improving the image for better recognition.
I used ImageMagick library and the filtered image looks like this :
But the Output of recognition is :
446929231986789 //The first and last numbers (4 & 9) were added
So I Want to detect only the white box to crop ...
I know that OpenCV do the trick but unfortunately it's C++ library and I don't speak that language :(
And I knew that iOS8 has a new CIDetector of type Rectangles but I don't want to neglect the previous versions of iOS
MY IMAGEMAGICK Filter CODE :
//Starting
MagickWandGenesis();
magick_wand = NewMagickWand();
//Reading the image....
NSString *tempFilePath = //Path of image
// Monochrome image
MagickQuantizeImage(magick_wand,2,GRAYColorspace,1,MagickFalse,MagickFalse);
// Write to temporary file
MagickWriteImage(magick_wand,
[tempFilePath cStringUsingEncoding:NSASCIIStringEncoding]
);
DestroyMagickWand(magick_wand);//Free up memory
// Load UIImage from temporary file
UIImage *imgObj = [UIImage imageWithContentsOfFile:tempFilePath];
// Display on device
Many thanks ..
I would go with simple pixel search. Since you want to crop the white area with digits all you need to do is to find left, right, top and bottom borders of the rectangle. Provided that rectangle is axis aligned and has enough white space around digits you should find first row or column that has continuous number of white pixels. For example to find left border (which I guess would be around 78th column) start searching from column 0 and go right. For each column count continuous white pixels (single for-loop from top to bottom). By continuous I mean series that is not interrupted by black one. If count will reach, say, 80% of height you have your left border. Do the rest accordingly starting from right side, top or bottom and move in the opposite direction. I guess there are some fancy procedures to detect the rectangle but your input has quite distinguishable characteristics. So instead of linking to some lib I suggest DIY. To speed things up you could increase your row by 2 or more. Or you could scale your image down, treshold it do 2 colors.
There is also one more way to do this. Flood-fill with white starting from one of the corners.
I'm working on a jigsaw puzzle webapp, and one of the requirements is automatically generating puzzle pieces from any image. I'm using RMagick for the image processing. I've got some sets of blank puzzle pieces to use as masks, and I can handle that part, but then I need to trim the whitespace (er, transparentspace) out of the resulting images.
Now, I know I can use trim for this - I might have to put a one-pixel border on it to make sure all four corners are the right color, but that's easy and I can just subtract one pixel from the final number. The only problem is that I also need to record the position of the piece. According to the documentation on trim, the function will "retain the offset information", which sounds like exactly what I need. But I can't find anything about how to retrieve the offset information! Does anyone know how to do that?
If worst comes to worst, I suppose I could always just look through pixel-by-pixel, find the boundaries myself, and use crop to trim the picture, but that wouldn't exactly be good for performance.
Aha, found it. image.page.x and image.page.y give the upper left corner, and then image.rows and image.columns have the height and width.
Hi there from the image below you will see some guides that are set 1mm apart but the pixel lines I have drawn are not aligned nor am I able to get them aligned to the mm. moving the lines with the anchor tool causes them to loses the solidness and bleed into other pixels. does anyone know away to get the pixels to align to the mm?
may just be something Im missing
example image
http://img401.imageshack.us/img401/51/ruleo.jpg
I'd suggest going to your Snap To settings under the View menu and seeing what is turned on or off in there.
You could definitely turn snapping off and manually match the elements up to the lines.
Can anyone share a sample code to draw a non-rectangular part of a picture in delphi canvas?
You're looking for GDI paths. Start here, which explains what paths are in this context, and provides links on the left to explain the functionality available with them.
Google can turn up lots of examples of using paths in Delphi. If you can't find them, post a comment back here and I'll see what I can turn up for you.
Your question is pretty vague. But I suspect what you are looking for is clipping regions. Read up on them. Set the clipping region on the target device to the shape you want, and then draw the image onto the device. Only the part of the image that would be within the clipping region will be drawn.
Canvas.Ellipse(0, 0, 10, 20); // not a rectangle
I use so called runlists for this feature (generalized shapes and blitting them). I've seen them called warplists too. A shape is encoded as a runlist by defining it as a set of horizontal lines, and each line is two integer values (skip n pixels,copy n pixels).
This means you can draw entire lines, leaving you with only "height" draw operations.
So a rectangle is defined (the first "skip" pixels from top level corner to the left corner (xorg,yorg). The rectangle is width_rect wide, and width_pixels goes a line further. width_pixels can be wider than the width of the picture (alignment bytes)
(yorg*width_pixels+xorg , width_rect),
(width_pixels-width_rect , width_rect),
(width_pixels-width_rect , width_rect),
(width_pixels-width_rect , width_rect),
..
..
This way you can make your drawing routines pretty generic, and for simple, regular shapes (rects, circles) it takes only minor math to precalculate these lists. It simplified my shape handling enormously.
However I draw directly to bitmaps, not to canvasses, so I can't help with that part. A primitive that efficiently draws a row, and a way to extract a row from a graphic should be enough.