Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a bunch of UIImages that consist of black and white book pages. I want to be able to "crop" or "cut" the image based on where the page ends (Where the white space begins). To illustrate what I mean, look at the image below. I want to crop the image programatically right after the word "Sie".
I am not sure how to go about this problem. I have gave it some thought however, perhaps detecting where the black pixels stop since it will always be black and white but not sure how to properly do this. Can anyone offer any insight or tell me how this may be done?
Thank you so much!
Here's some python code I wrote using the Python Imaging Library. It finds the lowest black pixel, and then crops the image five pixels down from that y value.
import Image
img = Image.open("yourimage.fileformat")
width,_ = img.size
lowestblacky = 0
for i, px in enumerate(img.getdata()):
if px[:3] == (0, 0, 0):
y = i/width
if y > lowestblacky:
lowestblacky = y
img.crop((0,0,width,lowestblacky+5)).save("yourimagecropped.fileformat")
Python is available on nearly all operating systems, so I hope you'll be able to use this. If you want to crop the image right after the last black pixel, simply remove the "+5" from the last line, or change the value to your liking.
Convert the image into pixel values. Start with the bottom line of pixels and look for black pixels. If some are found, the line is the end of the image. If there is no black pixel, continue to the next line of pixels.
Actually, "black" pixel is probably too simplified. A good solution would use a limit of gray (every image has some noise) or even better, a change in pixel contrast. You can also apply an image filter (e.g. Edge detection or sharpen) before starting the detection algorithm.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was playing with iOS built-in Compass app and the UI do make me curious.
Here is the interesting part:
The color of text (even the circle) can be partially and dynamically changed.
I have made a lot of search, but the results are all about attributed string. How to implement the effect like this?
Edited:
I have tried to add two UILabels (whiteLabel and blackLabel) as whitelabel at the bottom and blackLabel at the top with the same frame. Then I set the circle as the mask of blackLabel.
The problem is 'whiteLabel' is totally covered by blackLabel, and if the circle do not intersect with 'blackLabel', both labels are not visible.
I imagine that there are two "14" labels in the same place. The bottom one is white and unmasked, and the top one is black and has a layer mask that contains two circles, so it's only visible where the circles are.
Achieving this has most probably nothing to do with NSAttributedStrings, like Woodstock said.
I'd say it's the UILabel's layer that is recolored live, depending on what other layer it intersects with, and the overlaying area of said intersection.
Once you figure those common points, you just apply a mask that inverts colors from there.
Now it's a little bit more complicated than that since there appears to be two circles (hence two layers to find intersections with), but in the end, it's "just a list of coordinates" that the label's coordinates intersects or not.
That could be an interesting exercise ; it would probably take me a decent amount of tries to mimic that behaviour, but I'm pretty confident my reasoning is on point. (get it? :o)
I'm trying to get a bounding box for the word "ЛИЛИЯ" in this image, using opencv.
(source: litprom.ru)
I am already experimenting with cv::findContours() and different thresholding alogrithms for couple of days, but can not get any satisfying results.
So, what do I know about this word:
letters are of similar size;
letters' height is in range: 40px — 90px;
word is oriented horizontaly (±5˚);
there is one and only one word on this image;
this word does not intersect image's border (it's fully visible);
different parts of image may have different luminosity;
hotspots (totally white areas) may be present on an image.
English is not my native language, so I'm sorry if the question is not properly explained.
If someone needs more images to answer this question, I have at least a dozen more.
Check out stroke width transform. That is used to text detection.
You can preprocess your image with adaptiveThreshold. You should use a blocksize a little bit bigger than your biggest character. I tried on your image with 91 and it gave good results. Then you can use FindContours and filter the blobs/contours using their height. Note that the letters will still be connected one to another so you cannot really filter using the width.
I am using 4-Way floodfill algorithm.
I have a transparent image with black out line.
That is staring point image(without color).
And after filling the color in this image it look like this
Please help me and let me know what can i do for proper fill.
I used and implemented myself FloodFill in other projects and the algorithm goes trough the whole draw, looking for closed spaces and then draw inside (or outside) them.
Your problem happens with every tool in the world that fills a draw, and the problem is the same, the spaces are not 100% closed.
The floodfill algorithm goes pixel by pixel and when it detect a black pixel, it stops. For example, the arm of the scuba driver is not thick enough or it has holes on it, and the flood fill algorithm manages to go trough it and not detect it as an empty space.
Nobody here can tell you why unless we take your project and analyse it, so the best I can offer is a guideline about where your error could be.
I tried the code with an image that has a very precise defined border around it (from here) and it seems to work OK with that image. I suggest perhaps that if you zoom into your image that there is some grey aliasing around the edges which won't get filled. Perhaps the algorithm has a threshold function that can be tweaked?
Try setting the andTolerance value (I tried 4 which seemed to improve my example).
//Call function to flood fill and get new image with filled color
UIImage *image1 = [self.image floodFillFromPoint:tpoint withColor:newcolor andTolerance:4];
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I've a transparent PNG image i'm using for a button on a web page. I'd like to be able to replace the images text with some other text using Gimp 2. Any idea's how i can easily achieve this? I'm a complete novice to GIMP!
Your button has a top-down gradient but it should be easy to do the trick.
To get the job done, I'll suggest you to follow these steps:
obtain a template button, i.e. a button without text.
modify the template at will, to get button with any kind of text
addressing point 1
Please notice that the gradient of the button is vertical and homogeneous. This really simplify the work: simply, drag a little selection on the left side of the button big enough to cover the height of the text, as shown below
then you have to copy and paste the selection in a new layer (L1). Move the layer L1 to the right (use the arrow key to preserve vertical alignment) to cover the white text, then copy the L1 to a new layer (L2). Now you have another layer to put on the side of L1 to cover another piece of text. Iterate until the text is all covered. Now you can merge all the layers.
addressing point 2
You have your button template! The last thing to do is to add the text. Choose the text tool and position the cursor in the middle of the button to write the new label. I tried to reproduce the shadow effect of the original text by setting an internal shadow with 50% of opacity, 90 degrees direction and 1px of distance.
Here you can find the png template. I did this tutorial in PS for it is the program I have at hand.
You cant. PNG Text can't be changed when exported.
Create a Button.
Add Layers for each text you want to use.
Deactivate the the layers except the one needed and export.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I am making a desktop image editing software using Processing. It will allow the user to select the image to edit. The area in which the user can do the editing is a fixed 640 x 480 screen.
This means that I will have to scale the input image to fit the screen. That is easy to do with rectangular images. The problem arises when dealing with square images.
Programatically, 2500x2501 is not a square image. For all practical purposes it is.
How do I make sure that I properly scale these images ?
Calculate the aspect ratio (width / height, or vice-versa). I suggest dividing whichever is smaller by the other one, so you always get a number that is no greater than one.
Then define a threshold, as a number between 0 and 1. If the resulting division gives a result smaller than the threshold, you can consider the image a non-square.
Something along these lines...
var ratio = 1;
if(Height>Width)
{
ratio = (Height / Width);
}else{
ratio = (Width / Height);
}
var ThresHoldVal = 0.1; // 10% out.
if((Ratio-1) > ThresholdVal)
{
//Invalid.
}