-
Notifications
You must be signed in to change notification settings - Fork 62
-
https://libvips.github.io/libvips/API/current/libvips-mosaicing.html
I have a thousand of images that all have different amount of matching so I probably can't come up with universal numeric arguments.for vips_match. Also I can't tell I understand them at all. When I had a look on docs previously I believe I saw a function that produces a 2d bw map of level of matching between two images so I could then decide what do to with it. But I probably can't find what function that was and the...
irb(main):005:0> im11.match(im12)
Vips::Error: unable to call match: you supplied 2 arguments, but operation needs 10.
just tells me I need something different.
UPD: something like this: https://stackoverflow.com/q/36688439/322020
I believe I saw such function...
Or maybe that was match but I imagines it to work simplier when I was reading docs the last time.
UPD2: Or I guess it was spcor. After scaleimage (btw, is it per band?) gives me such image:
but takes eternity to correlate two 1280x720 images while I have a thousand of them...
UPD3: oh, and I just realised that it's only trying one quarter of relative shifting so I need to do it 4 times, right?
rd = img11res.fastcor(img12res) ru = img11res.flipver.fastcor(img12res.flipver).flipver ld = img11res.fliphor.fastcor(img12res.fliphor).fliphor lu = img11res.fliphor.flipver.fastcor(img12res.fliphor.flipver).fliphor.flipver Vips::Image.arrayjoin([lu,ru,ld,rd], across:2).scaleimage.write_to_file "temp.png"
image
does not look right...
Maybe I don't understand how it's supposed to work. It makes no sense to me.
a = Vips::Image.new_from_array [[0,0,0,0,0],[0,1,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
b = Vips::Image.new_from_array [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,1,0],[0,0,0,0,0]]
Vips::Image.arrayjoin([lu,ru,ld,rd], across:2).scaleimage.write_to_file "temp.png"
Beta Was this translation helpful? Give feedback.
All reactions
I guess I tried the wrong function. phasecor seems to be what I need:
img12res.phasecor(img11res).stats.to_a.drop(1).transpose[8,2]
=> [[[0.0], [0.0], [0.0]], [[23.0], [23.0], [23.0]]]
These as I understand are the shifting candidates per band.
What I don't yet understand is why it's #<Image 160x90 double, 3 bands, b-w> -- being b-w but with 3 bands makes the .write_to_file save both dark and light pixels as white. (削除) How do I switch the interpretation? (削除ここまで) .copy(interpretation: :srgb)
P.S.: and it's weird that when I call it on two similar (i.e. no shift needed) or even identical images it's all a noise and no bright pixel in the left-top corner.
P.P.S: also there is a true point and three fa...
Replies: 2 comments 3 replies
-
Yes, spcor is very slow -- it computes the full normalized spatial correlation, so 1.0 is perfect correlation and 0.0 is perfect mismatch.
There's vips_fastcor() -- it just computes sum of squares of differences, so you get 0 for a perfect match and some huge number for a perfect mismatch.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yep, I tried both. But I don't understand why those 4 results don't assemble smoothly. And absolutely don't understand the last example with two 5x4 images that should match when shifted by (2,1).
Beta Was this translation helpful? Give feedback.
All reactions
-
I guess I tried the wrong function. phasecor seems to be what I need:
img12res.phasecor(img11res).stats.to_a.drop(1).transpose[8,2]
=> [[[0.0], [0.0], [0.0]], [[23.0], [23.0], [23.0]]]
These as I understand are the shifting candidates per band.
What I don't yet understand is why it's #<Image 160x90 double, 3 bands, b-w> -- being b-w but with 3 bands makes the .write_to_file save both dark and light pixels as white. (削除) How do I switch the interpretation? (削除ここまで) .copy(interpretation: :srgb)
P.S.: and it's weird that when I call it on two similar (i.e. no shift needed) or even identical images it's all a noise and no bright pixel in the left-top corner.
P.P.S: also there is a true point and three false points and they are I don't know how to chose one because they all are of the same intensity. For example, here the true one is the left bottom:
image
Beta Was this translation helpful? Give feedback.
All reactions
-
So I decided to just chose the one of 4 shifts by the lowest (rect1-rect2).abs.avg.
Then I used embed and bandrank and got this:
image
The new problem is that taking "median" among several images using bandrank may take the black color while I would like to discard it. Like if here https://www.rubydoc.info/gems/ruby-vips/Vips/BlendMode was such blendmode as "discard black and pick the one closest to the average". Otherwise the median results in this for now:
image
Or if I chose the index:images.size-1 it results in a mess:
image
Beta Was this translation helpful? Give feedback.
All reactions
-
To illustrate the result of "discard black and pick the one closest to the average", here is a rough implementation on Ruby level (that is obviously ~100 times slower i.e. unusable):
image
Beta Was this translation helpful? Give feedback.