Hot answers tagged

46 votes

Increase performance creating Mandelbrot set in python

I'm going to reuse some parts of the answer I recently posted here on Code Review. Losing your Loops (Most) loops are damn slow in Python. Especially multiple nested loops. NumPy can help to ...
user avatar
  • 7,184
37 votes
Accepted

Converting JPG images to PNG

Not much to improve upon, just some minor housekeeping. Help the end user! If I was using this script, and forgot to put one or both of the filepaths when calling the script, there would be this ...
user avatar
  • 9,642
31 votes

Converting JPG images to PNG

The variable names path1 and path2 are bad since they are not as descriptive as possible. They should rather be ...
user avatar
27 votes
Accepted

Julia Fractal Drawing in C++

Unqualified names The namespace identifier is missing from a lot of names - e.g. std::sqrt, std::log, ...
user avatar
  • 58.1k
23 votes

Python 3 function to rotate an image 90°

You can use NumPy module that's good with arrays and matrices. It has a built-in for exactly that purpose - ...
user avatar
  • 886
22 votes
Accepted

Python 3 function to rotate an image 90°

I believe the time complexity is \$O(n^2)\$, but I'd like to know for sure There's a general method for figuring out the time complexity for a piece of code, which is to annotate each line with the ...
user avatar
  • 49.2k
20 votes
Accepted

Resizing image but keeping aspect ratio

Your algorithm to calculate the final image dimensions could be improved by simplifying the logical process that you use to determine the final size. Fundamentally, there are two dimensions you are ...
user avatar
  • 96.8k
20 votes

Increase performance creating Mandelbrot set in python

This will cover performance, as well as Python style. Save constants in one place You currently have the magic numbers 2000 and 3000, the resolution of your image. Save these to variables perhaps ...
user avatar
18 votes

Fastest way to clamp an integer to the range 0-255

Conclusion 2011-12-05: I tried all of the suggestions again with VS 2010 Express. The generated code didn't change much, but the register assignments did which affected the overall results. A slight ...
user avatar
  • 1,806
17 votes
Accepted

Change desktop background

These using directives are not needed and can be safely removed: ...
user avatar
17 votes
Accepted

Detecting a certain amount of violet in an image

Try using HSV/HSL to represent color instead of RGB. You can then define violet as some hue range, e.g. 250° to 310° and similarly for saturation and lightness/value. Always use a ...
user avatar
  • 2,909
16 votes

Converting JPG images to PNG

Apart from what's already mentioned I would like to point out that the file super.picture.jpg will be converted to super.png ...
user avatar
15 votes
Accepted

Slow image generation

Like I said before, the reason why this takes a lot of time is because the number of steps is proportional to the square of the number of disks. But there are some other improvements to be made to ...
user avatar
14 votes

Get image from other site in PHP

Your code is vulnerable to LFI and XSS. http://localhost/yourscript.php?url=../../../../../../etc/passwd This would load the local file /etc/passwd and display ...
user avatar
  • 24.9k
14 votes

Classifying image by file extension within a PDF creator

Naturally, you can use a dictionary to map extensions to file types: "jpg" -> ImageFileType.Jpeg "jpeg" -> ImageFileType.Jpeg "...
user avatar
  • 107k
14 votes
Accepted

OpenCL implementations of IQZZ and IDCT for MJPEG

Indent your loop bodies. Actually check ret - you're uselessly assigning and discarding it every time. Use better variable names: avoid single letters (...
user avatar
  • 831
14 votes

Determine if an image is opaque or transparent

I don't know how good the C# compiler and runtime optimize this code out of the box, so here is what I would try: Load bitmap.Width, ...
user avatar
14 votes

Julia Fractal Drawing in C++

There's already a good answer, so I'm just going to raise a couple of small points. I had the same thought as Toby Speight about saving the square root of abs(z), ...
user avatar
14 votes

Maze generator & animator in Python

This is a tip I make a lot, but if you have a collection that's simply tracking "membership", and you don't care about order, you should consider using a Set over a List. I think this is the case for ...
user avatar
13 votes

Checking CSS code for best practices when mimicking

Here is my CSS Well, no, actually. That's your HTML - it just happens to have some style attributes. Which it shouldn't have. So step one, separate CSS and HTML. ...
user avatar
  • 32.9k
13 votes
Accepted

Imaging with getPixel() and loops

The ´var´ keyword: From the C# Programming Guide: The var keyword can also be useful when the specific type of the variable is tedious to type on the keyboard, or is obvious, or does not add to ...
user avatar
  • 5,553
13 votes

Determine if an image is opaque or transparent

Readability The readability of the code could be slightly improved by adding a new line before the unsafe. Assigning the ...
user avatar
  • 50k
13 votes
Accepted

Determine if an image is opaque or transparent

Performance can definitely be improved, but it's a case of how far you want to take the tradeoff. First, though, note that Bitmap is ...
user avatar
13 votes

Processing an image to extract green-screen mask

Use conditional indexing: ...
user avatar
  • 12.2k
13 votes
Accepted

Hough transform algorithm - Idiomatic c++

Here are some suggestions for improving the code. Use all required #includes The code uses vector but doesn't include the ...
user avatar
  • 64.5k
12 votes
Accepted

Speed optimization for transparent gradient blend algorithm

There are a number of things you could do to make this faster and better. Use a pointer rather than array references The code currently computes a pixelIndex and ...
user avatar
  • 64.5k
12 votes

Mandelbrot image generator

Several things: I compiled your code on my Linux host (Centos 7) using gcc version 4.8.3 via the command line: ...
user avatar
  • 371
12 votes
Accepted

Processing an image to extract green-screen mask

There's a simpler way to create the empty image using numpy.zeros_like: empty_img = numpy.zeros_like(img) As Austin Hastings ...
user avatar
12 votes

Increase performance creating Mandelbrot set in python

Mandelbrot-specific optimisations These can be combined with the Python-specific optimisations from the other answers. Avoid the redundant square root ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible