Reputation
12,123
Next privilege 15,000 Rep.
Protect questions
Badges
2 30 61
Newest
 Nice Answer
Impact
~144k people reached

Apr
15
comment Efficient way to perform local Otsu thresholding on image
as a workaround, you could calculate thresholds for every nth pixel, and interpolate in between.
Apr
7
comment Looping within linear programming
Also, // does not start a comment in Mathematica code!
Apr
7
comment Looping within linear programming
This question would be much clearer if you posted the code that actually takes too much time. I've tried your first two code blocks, and neither takes more than a few milliseconds. Without that, the only tip that comes to mind is use FindMinimum instead of Minimize. Minimize tries to solve the problem symbolically, which is in general more expensive. FindMinimum uses local optimization, which is usually fastest, and for an LP is guaranteed to find the global minimum.
Apr
5
comment Is association in mathematica ordered or not?
@Nasser: It's not the most frequent use case, but sometimes you want to aggregate data in an Association, then later process the key/value pairs in the order they were discovered. And I often find it handy that BarChart, ListPlot&friends don't jumble association data I pass them. So I'm glad Wolfram made them ordered.
Apr
5
comment Ordered associations
Not exactly a reference, but Sort and KeySort return sorted associations (and that's documented behavior). That wouldn't make any sense if associations were unordered.
Mar
24
comment Extracting road curves from an image
@P.Fonseca: I tried, but exported as gif the animation was ~30 MB... (swf and qt were both between 1-2 MB)
Mar
24
comment Extracting road curves from an image
@Pickett: Weird. The documentation doesn't say that this syntax is new, and I could have sworn I've used it like this since v8. OTOH, the speed difference isn't that large (in this case) so I'll change it to your version.
Mar
24
comment Extracting road curves from an image
@Pickett: Weird. I've just executed the code in a fresh MMA session, and except for the Show-problem Zviovich mentioned, it worked fine. Does whitePixels contain a list of 2d coordinates in your session? Or maybe -> Automatic syntax is newer than your MMA version?
Mar
24
comment Extracting road curves from an image
@Zviovich: I've used bgnd=Image[bgnd], to make my experiments with colorDist faster. I didn't realize this changed the behavior of Show. I've updated my answer. Regarding the title: Maybe something like "Extracting road graphs from an image"?
Mar
9
comment Can I solve this graph theory problem with Mathematica?
I see. The solution got lost in translation...
Mar
9
comment Can I solve this graph theory problem with Mathematica?
Which number is which? Could you maybe draw one of them in a graph? I thought they were top-to-bottom, left-to-right, but then 4,5 in the first example would be neighbors.
Feb
11
comment Using 2D Fourier transform of an image to detect typical wavelengths
@SjoerdC.deVries is right, I didn't notice that. IIRC, this is done to "rotate" the 0 frequencies to the center of the FFT output. If you want to interpret the values numerically (instead of displaying the FT as a picture), you'd want to remove that line.
Feb
11
comment Using 2D Fourier transform of an image to detect typical wavelengths
fw contains the values. I.e. fw[[1,1]] is the value for frequency 0/0, fw[[1,2]] is the value for frequency 0/1...
Feb
7
comment Efficient Lloyd Sampling of Images
Calculating the distance to the nearest seed for each pixel, good idea, I didn't think of that! It might get slower if nx and ny get large (10^4? 10^5?), but for 200, it's pretty fast. I don't have time to update my answer right now, but I think Nearest[seeds -> Range[Length[seeds]], pos][[All, All, 1]] is even faster than your Compiled code.
Feb
7
comment Efficient Lloyd Sampling of Images
@paw: It seems as if Rasterize[Graphics[...]] creates an 8-bit image, and using GrayLevel[index/200] leads to rounding errors. GrayLevel[index/255] seems to work better; If you have more than 255 seeds, you'll have to use RGBColor to encode the seed index. Also, I've noticed that the seed centers seem to be "moving downwards" - I'm guessing Polygon and ComponentMeasurements are rounding in different directions - that's why I've added the (admittedly, ugly) -1 in the PlotRange
Feb
7
comment Efficient Lloyd Sampling of Images
@belisarius: Using image processing to approximate a Voronoi diagram is much more expensive than actually calculating a Voronoi diagram. At least in 2d, calculating a VD is about as complex as sorting all the points by their Y-coordinate.
Jan
16
comment Plotting y'[x] vs y[x]
ParametricPlot?
Jan
14
comment How can I detect if an image is in or out of focus?
Related: stackoverflow.com/questions/7765810/…
Jan
12
comment How can FactorInteger be so slow if PrimeQ is fast?
@DanielLichtblau: reading an 8th grade math book might lead one to believe that factorizing an integer is the only way to find out if it's prime ;-)
Jan
9
comment Can I force Mathematica to use machine precision?
Thanks @OleksandrR., SystemSetSystemOptions["CatchMachineUnderflow" -> False];` works perfectly. I did look for similar questions, but didn't find the one you linked. It's obviously a duplicate. Should delete it myself or vote to close?