47
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 ...
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 ...
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 ...
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, ...
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 -
...
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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
"...
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 (...
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, ...
14
votes
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), ...
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 ...
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 ...
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 ...
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 ...
13
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, ...
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 ...
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
...
12
votes
11
votes
Accepted
Turning music into an image
Strange loop initialization
Hm, what's up with this loop initialization?
for (int i = i; i < 12000028; i++) {
i is not ...
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 ...
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 ...
11
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
image × 719performance × 177
python × 168
c# × 94
javascript × 94
c++ × 78
java × 61
beginner × 58
python-3.x × 58
php × 58
c × 55
algorithm × 48
jquery × 41
opencv × 34
numpy × 33
html × 22
file × 20
android × 19
object-oriented × 17
css × 17
animation × 17
graphics × 17
array × 16
.net × 16
matrix × 16