Closed RiskoZoSlovenska closed 2 years ago
Hello @RiskoZoSlovenska,
Yes, spcor
is extremely slow. It's doing a full normalised spatial correlation. There's fastcor
if you just need to find the position of something -- it only computes sum of squares of differences.
The speed difference is because of caching. libvips memoises operations, so if you call the same operation with the same arguments on the same image, you get the previous result again.
Ah, I see, thanks for the clarification. I guess I was just expecting the :spcor()
call itself to be slow. Either way, I think you're right - fastcor
should be sufficient for what I'm trying to do. Thanks again for your time.
Slightly unrelated, where's the best place for me to ask these sorts of questions? Should I ask them in this thread, or create new Issues, or go to the Discussions at the libvips repo, or is there some other community server?
Yes, libvips is demand-driven, so the spcor is only computed when you use the result.
If questions are specific to Lua, then this is the best place. For general libvips questions, open a discussion in the Q&A section of the libvips site.
While messing around, I stumbled upon a peculiar occurrence: calling an operation on an image obtained by
:spcor()
is very slow, but only the first time the operation is called. To illustrate:Output:
I'm asking mostly just to satiate my own curiosity (I assume this phenomenon occurs due to some internal technical details), but I'm also wondering if it's possible to mitigate this slowness; the only workaround I've been able to find is to shrink the images before calling
:spcor()
. I've tried to save the image to file and then read it back into memory, only for the write operation to take ~8 seconds and the resulting:max()
on the loaded image to be instant. Casting the image to theuchar
format gave me the same results. Trying to loadtest1.png
with sequential access throws anout of order read
error, but I assume that's because:spcor()
can't work with it.I'm on version 8.12.1