-
Notifications
You must be signed in to change notification settings - Fork 62
-
I have some 1 band image. it is periodically (step=8) brighter in rows and cols. I want to suppress this periodical trait to remove the "grid". How do I do it in the most perfomant way?
I thought I should start with summing by rows and cols. I tried to do it by resizing but for some reason I've got values of -1
-- is it ok or is it some corner case bug?
irb(main):062:0> t.resize(1r/t.width, vscale: 1).to_a.take(10)
=> [[[-1]], [[-1]], [[-1]], [[-1]], [[-1]], [[-1]], [[-1]], [[1]], [[1]], [[-1]]]
irb(main):064:0> t.resize(1, vscale: 1r/t.height).to_a[0].take(10)
=> [[-1], [-1], [-1], [-1], [-1], [-1], [-1], [-1], [-1], [-1]]
UPD: I suppose I've found a proper method:
irb(main):066:0> t.shrinkv(t.height).to_a[0].take(10)
=> [[0], [0], [0], [0], [0], [0], [0], [0], [0], [0]]
irb(main):069:0> t.shrinkh(t.width).to_a.take(10)
=> [[[0]], [[0]], [[0]], [[0]], [[0]], [[0]], [[0]], [[1]], [[1]], [[0]]]
I wish there was a fast method to do the opposite. resize
back to original size (to then subtract/divide/whatever) seems to be slow.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 2 replies
-
Or actually maybe the really proper method to collapse the image to a row/column is vips_project
.
Anyway, I've switched from that project for now.
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry @Nakilon, I was in a flat panic 18 days ago on a deadline and I must have forgotten to come back to this. I'll have a look now.
Beta Was this translation helpful? Give feedback.
All reactions
-
No worries. That was a pretty blind experimenting about making metrics out of images and jpeg compression was the thing I wanted to fight. But I've got other metrics and decided to not dig here further for now.
Beta Was this translation helpful? Give feedback.
All reactions
-
You can use shrink
and zoom
to do very fast integer scaling.
y = x.shrink(10, 1)
y
will be 10x smaller horizontally and each column is the average of the 10 pixels in the input. zoom
does the inverse:
y = x.zoom(10, 1)
Now y
is 10x larger and each column in the output is repeated 10 times.
Perhaps I don't understand the problem exactly though -- post a sample image if I've misunderstood.
Beta Was this translation helpful? Give feedback.