Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
48 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 ...
AlexV's user avatar
  • 7,260
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 ...
Linny's user avatar
  • 10.1k
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 ...
Roland Illig's user avatar
  • 21.3k
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, ...
Toby Speight's user avatar
  • 75.7k
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 - ...
Divakar's user avatar
  • 896
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 ...
Gareth Rees's user avatar
  • 49.6k
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 ...
Reinderien's user avatar
  • 62.1k
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 ...
Johnbot's user avatar
  • 2,974
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 ...
CharybdeBE's 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 ...
Maarten Fabré's 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 ...
tim's user avatar
  • 25.1k
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 "...
janos's user avatar
  • 111k
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 (...
OrangeDog's 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, ...
Roland Illig's user avatar
  • 21.3k
14 votes

Processing an image to extract green-screen mask

Use conditional indexing: ...
aghast's user avatar
  • 12.4k
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), ...
Peter Taylor's user avatar
  • 24.1k
14 votes

Increase performance creating Mandelbrot set in python

Don't use vectorized numpy, use numba jit instead Using numpy to calculate the Mandelbrot set is not really a good fit because the same data will be stored and loaded from and to memory repeatedly, ...
John's user avatar
  • 241
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 ...
Carcigenicate's user avatar
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 ...
Heslacher's user avatar
  • 50.4k
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 ...
Peter Taylor's user avatar
  • 24.1k
13 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 ...
Dan Mašek's user avatar
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 ...
Edward's user avatar
  • 66.4k
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 ...
trichoplax is on Codidact now's user avatar
12 votes

Make an image where pixels are colored if they are prime

There are some things I would comment on, outside of what DeathIncarnate said in their answer. The is_prime is fine, I would change two small details: It is ...
Cris Luengo's user avatar
  • 5,613
12 votes

Image Processing Application in C

Enable more compiler warnings: ...
Harith's user avatar
  • 6,696
11 votes
Accepted

Square root image filter tool in Python

PEP 8 specifies four spaces per level of indentation. Since whitespace matters in Python, this is a pretty strong convention. You should round() the results to ...
200_success's user avatar
11 votes

Converting JPG images to PNG

Consider using __main__ to make your script easier to import (see here ). Also, consider the use of functions to isolate the different steps, so that it is easier ...
bracco23's user avatar
  • 384
11 votes

Image Processing Application in C

Size to the object, not type Rather than sizeof(Pixel), use sizeof image->pixels[0]. It is easier to code right, review and ...
chux - Reinstate Monica's user avatar
10 votes
Accepted

Program for face recognition

You should read and follow PEP8. This means: Put all imports at the top of the file. Put a space around assignment operators. Place a space after most commas. Use descriptive names. This is as it ...
Peilonrayz's user avatar
  • 43.4k

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