Re: Challenge: Speed up seam carving example
Hi, cool stuff :-). This is not a large improvement, but you can gain a little by removing all pixels of a path at one time, by ravelling the array and using fancy indexing. Something like sx, sy = img.shape inds = np.arange(img.size) removed_inds = p + row_idx * sy img = img.ravel()[np.setdiff1d(inds, removed_inds)] img.shape = sx, sy - 1 Also, is it possible to compute at one time several shortest paths from one side of the array to the other (using MCP), and removing several paths during a single iteration? You might have problems when paths intersect, because then you don't have the same number of pixels to remove for each line, but you might choose a rule for such cases (e.g. removing the pixel on this line that belongs to the next path that would be removed) and maybe it won't be so bad... I don't know, I guess I should have watched the video before giving my advice ;-) Emma On Sun, Oct 09, 2011 at 03:48:20AM -0700, St�fan van der Walt wrote:
Hi all,
I have placed an example of seam carving here:
https://github.com/stefanv/scikits.image-1/blob/seam_carving/doc/examples/pl...
The idea is super simple, but currently it's too slow. I'm curious to see if anyone can improve its execution time?
If you haven't seen seam carving before, take a look at the video link in the docstring.
Regards St�fan
On Sun, Oct 9, 2011 at 7:53 AM, Emmanuelle Gouillart
This is not a large improvement, but you can gain a little by removing all pixels of a path at one time, by ravelling the array and using fancy indexing. Something like
sx, sy = img.shape inds = np.arange(img.size) removed_inds = p + row_idx * sy img = img.ravel()[np.setdiff1d(inds, removed_inds)] img.shape = sx, sy - 1
Nice idea, thanks!
Also, is it possible to compute at one time several shortest paths from one side of the array to the other (using MCP), and removing several paths during a single iteration? You might have problems when paths intersect, because then you don't have the same number of pixels to remove for each line, but you might choose a rule for such cases (e.g. removing the pixel on this line that belongs to the next path that would be removed) and maybe it won't be so bad...
I also thought about this idea, but couldn't figure out how to solve the intersecting lines without some for loop. I don't mind writing it in C, but that's not ideal for an example! Also, I thought about just erasing lines from the edges and the image at the same time, instead of re-computing the edge detection, but that's not valid. Stéfan
participants (2)
-
Emmanuelle Gouillart
-
Stéfan van der Walt