Filling a hole in an image in O(nlogn)

I have a grayscale image (given by a float matrix with values between [0, 1]) with a hole in it (a cluster of pixels/cells with values of -1).


The boundary of the hole as all the cells that are 4-connected to a hole pixel (a pixel with -1 value) (you can read more about pixel connectivity here:

I(v) is the color of the pixel v.

I need the fill the hole using this formula:

Denote the boundary with B. So for each u – hole pixel:

\begin{equation} I(u) = \frac{\Sigma_v{_\in}_B w(u,v) * I(v))}{\Sigma_v{_\in}_B w(u,v)} \end{equation} Where w is some arbitrary weighting function (for example using euclidean distance)

\begin{equation} w(v,u) = \frac{1}{|| u – v||} \end{equation} Denote the number of hole pixels with n, the naive solution will be O(n^2), since for each hole pixel, we sum over all boundary pixels (and the upper bound for the amount of boundary pixels is 4n, of course).

I was told a solution could be achieved in O(nlogn), but I couldn’t think of anything even close to that.

I thought of doing some bitwise operations, but I reached a dead end. I also tried reusing computations, but I couldn’t find any.

Moreover, the way I see it, there’s no avoiding calculating w(u,v) for the n^2 pairs of hole/boundary pixels – which is already more than O(nlogn).

What am I missing? Could you point me at the right direction?


What options are available to a Portable Hole owner?

I am a new DM, trying to understand the magic of the Portable Hole. I’ve read through as many previous posts on Portable Hole shenanigans as I could, but none seem to answer my questions. One of my players has managed to find a Portable Hole, thanks to the random loot tables. He’s familiar with them due to having played earlier versions of D&D. I, having never played these versions, am not as familiar. We find ourselves at odds on just how this item works. In order to keep this post short, I won’t post my interpretation of the rules, though suffice to say I disagree with the following.

  1. The Portable Hole can be opened by two people, holding it open like a sheet.

  2. If even the smallest portion of the cloth is opened, the portal is opened and the character can reach into the extra dimensional space.

  3. The Portable Hole can be thrown upwards, and unfold on its way back down, therefore opening the portal.

Do the rules shed any light on these complicated questions?

Can a portable hole be used on a shield?

If I fixed a portable hole on the front of a large flat shield, looking at the front of the shield, I would see a a 5 foot deep hole. BUT, looking at the shield from behind, would there also be a hole? Would the back be flat and untouched?

Would arrows shot into the hole re-appear 5 feet behind me? Would they just disappear?

I’m sure standing behind the shield, the arrows would not hurt me, as the ground or walls a hole is affixed to are unharmed after the hole is removed, so no permanent damage is done.

From the front, would the hole be limited by the thickness of the shield? Would the hole extend 5 feet back through empty space leaving a hole in my torso?

Would the hole GLUE things into a fixed position behind it? Like an invisible thumbtack made of negative space? Because a hole in a wall opens a space to hide in, crawl through, but how solid are the walls? you cant go sideways inside a hole, but is this because you are in a rock wall, and the unaffected rock is blocking your path? or is the hole itself the unmovable wall? Would there be no resistance, if there was no physical material blocking your path? i.e. COULD an outside object enter hole-space from the side, if there was NOTHING there to block entry?

To make positional questions easier, z-dimension is the depth of the upright hole, front to back, and x is shoulder to shoulder, Y-dimension up and down.

If I stood behind the shield (say, 5mm thick?), would the dimensional hole cause me to be separated from my lungs? If so, would they still function on the other plane? Would blood flow cross the threshold in x/y directions unhindered? Would a solid force stop my heart/lungs from oxygenating the rest of my body? Would it continue to work as expected, but just do so invisibly? Would I be “thumbtacked” into position and held, until someone in the front peeled the hole away? Could I come and go from behind the shield at will, because the dimensional adjustment only applies to the front surface of the shield along the x/y axis’ leaving the back unaffected?

How Do You Accurately Price A Portable Hole?

Using the Estimating Magic Item Gold Piece Values table on page 285 of the DMG, how do you accurately price a portable hole on page 264 of the DMG. I am trying to find the accurate pricing formula for a standard portable hole so that I can then just increase the caster level of the item. Currently, a portable hole has plane shift that is a Sor/Wiz Spell of 7th level or a cleric spell of 5th level and a caster level of 12.

I am assuming that they used the level of the creator cut it in half to get the 6-foot diameter of the portable hole; so if you made the hole when at 20th level it would then make the diameter of the hole 10 feet.

What I am trying to figure out truly is a price for the increased manifester level of the same item.

How is the bag of holding in any way preferable to a portable hole?

The Portable Hole creates an extradimensional space that is 6 feet wide in diameter and 10 feet deep. It can be folded to the size of a handkerchief, weighs effectively nothing no matter what is carried in it, and has no weight limit as to what can be put inside of it. It requires one action to spread it on the floor and access it. The description says nothing about being able to damage or cut the hole with typical weapons. Beings in the hole can breathe for 10 minutes before beginning to suffocate, with no mention going towards how many creatures are in the hole.

The Bag of Holding contains an extradimensional space that is 2 feet wide in diameter and is 4 feet deep. It is about the size of a regular carrying bag, weighs 15 pounds regardless of what’s put in it, and has a 500 pound weight limit as to its contents. It requires one action to reach into the bag and pull something out. The description also mentions that if the bag is pierced, such as with a sword, the bag will rupture, and all its contents will be ejected into the astral plane, with the bag itself being rendered unusable. Breathing creatures inside the bag can survive up to a number of minutes equal to 10 divided by the number of creatures (minimum 1 minute), after which time they begin to suffocate.

With all of these factors taken in, it seems like the portable hole is in every way better than the bag of holding – bigger, more easily carried, even allows breathing for longer apparently. Yet all I hear from adventurers these days (at least those in my group) is “can we have a bag of holding? Can we have a bag of holding? Can we have a bag of holding?” I’m sorry, but I’m stumped –

How is the bag of holding in any way better than a portable hole, other than its iconic nature in the history of D&D?

How to ensure Windows 10 is safe from critical security hole reported by NSA on 2020-01-14?

All over the news today (2020-01-14) is the story that the NSA and Microsoft have reported a critical security vulnerability in Windows 10.

But I haven’t been able to find clear instructions about how to ensure that Windows Update has worked properly.

When I click the Start button and then then type “winver” and click “Run command”, I see that I have Windows 10 Version 1803 (OS Build 17134.191)

Windows > Settings > “Update & Security” > “See what’s new in the latest update”, it bounces me to, which doesn’t seem to mention security at all.

The Windows Update feature itself seems flaky, confusing, and unreliable.

I’m the most tech-savvy in my large extended family, and I generally try to help others (especially older generations) keep their systems working well, but right now I’m struggling to find a set of steps I can walk them through to confirm that their systems are no longer vulnerable.

Portable Hole vs Bag of Holding vs Handy Haversack – differences other than size/weight?

I’ve got a kleptomaniac in my group who’s constantly picking up entire armfuls of junk to bring back to town or squirrel away for a rainy day. I want to gift her some kind of carry-all to assist in the junk-holding, but scouring item lists has turned up three different potential options, all of which seem roughly similar other than their respective total volumes.

  • Portable Hole has a 3.14 x 10 x 9ft^3 (~270 cubic feet) space with no weight limit
  • Bag of Holding has a 3.14 x 1 x 4ft^3 (~12 cubic feet) space with a 500lb weight limit
  • Handy Haversack has a combined .75 x 4 x 4ft^3 (~12 cubic feet) space with a combined 120lb weight limit (I think, I am very bad at math)

My intention is to reskin one of the items as a tapestry that’s being used as a cloak by a puma. (Isn’t D&D great?) I want them to be able to put things into the tapestry and also retreive them at will later. Other than that it’s pretty flexible.

Am I overlooking a difference between the Portable Hole, Bag of Holding and Handy Haversack that would make one item significantly better suited to this purpose than the others? If size and weight are the only relevent parameters then it’s an easy enough choice but I can’t help but shake the feeling that I’m missing something.

What’s the orientation of the Rope Trick hole?

The Rope Trick spell specifies

Holding one end of a 60-foot or shorter rope causes the other end to rise up until the rope is fully perpendicular to the ground. At the high end, a portal opens to an extradimensional space into which eight medium or smaller creatures can fit by climbing up the rope. The rope can also be dragged up into the space to hide the entrance and the portal itself is invisible.

Spells and attacks are unable to enter or exit the extradimensional space, but those within can see out of it as through a 3 by 5 foot window centered over the high end of the rope.

If everything inside the extradimensional space has not exited beforehand, it will fall out when the spell ends.

Our group has been playing under the assumption that the window is positioned vertical relative to the ground plane, because that’s the way most windows we see are positioned. This would mean that you climb into the hole as if on top of a cliff edge at the end of the rope and you then have a view of the world as if you’d be looking out of any normal building window.

However, this seems to be in contradiction with popular depictions on the internet.

The difference would be surprisingly relevant to some standard strategies we have been employing.

How is the Rope Trick portal positioned relative to the ground plane/gravity/the rope?

Is directly echo the php server variable for user agent a security hole?

Is this script vuln to php/js code injection? In my quick test i changed the useragent to a php script but it will not be executed just printed. if change user agent to a javascript code i receive i connection refused by the webserver.

so am i safe with this type of script?

<?php  $  u=$  _SERVER['HTTP_USER_AGENT'] ?> <html> <pre>string</pre> <?php echo $  u; ?> </html>