YOUR ACCOUNT

Login or Register to post new topics or replies
Borkus McJorkus
Posts: 45
Filters: 14
Hey, folks. I've got what seems like a simple request. Whether it's as simple to execute as it is to describe... well, we'll see.

What I'm looking for specifically is a filter that analyzes the pixels in an image consisting only of black and white (no gray!) pixels and replaces white pixels bordered by eight black pixels.

In other words, let's consider three 3x3 pixel blocks, where "X" = a black pixel (RGB 0,0,0) and "O" = white pixel (RGB 255, 255, 255):

XXX OXX XXX
XOX XOX XXO
XXX OXX OOX

The filter I need would seek out the white pixels (0) with no adjacent white pixels and replace those solitary white pixels with black (X). So the result of applying this filter to those blocks above would result in:

XXX OXX XXX
XXX XOX XXO
XXX OXX OOX

The white pixel in the first block is turned black because it has no white neighbors. However, the white pixels in the second and third blocks remain unchanged. Make sense?

Okay... so. How to do this?


Thanks for your time.

-- McJ
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Hi Borkus,

Filter Forge uses a 'sample based' architecture, which means that it doesn't deal with the actual pixels directly. (Instead it samples a point, and then decides what the color should be. This allows you to zoom and rotate smoothly, for examples.)

That said, I think you could do it w/ offsets. Just figure out what the offset is, and use 8 if-then statements to find it.

OR there's probably some clever scripting way to do it (but that's over my head at the moment!) smile:?:
  Details E-Mail
tigerAspect
Posts: 222
Filters: 9
Once we get the bitmap-based Script component it'll be as simple as a single for loop. (Probably)
I'm not up on LUA at the moment because all the effects I'd want to write are bitmap-based, otherwise I'd give you at least pseudo-code...
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
This should be possible using the map script. The main "problem" is how to get from sampling coordinates to pixel coordinates (so you can get the precise pixel neighbours). We can find the sampling width of a pixel via SIZE variable (i.e. 1 / SIZE).

The attached filter should work as you describe..

Despeckle.ffxml
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Here's my attempt at it. It's clunky an inelegant, but it sort of works. I say sort of b/c it gets most of the image right, but there are a few areas where it will mis-identify an area surrounded by 7 as being surrounded by all 8.

A neat side-discovery is at the bottom: a way to identify horizontal and vertical lines.

Pixel Comparison.ffxml
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Grr... what the @#$% is going on w/ the attachments? smile:?:

Props to Sphinx, unlike mine, his version actually works! smile:D
  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Oh, my! Sphinx, this rocks so hard! Just what I needed!

And Corvus, much thanks for your work, but I don't really understand how to use it. Any pointers?

-- McJ
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
>And Corvus, much thanks for your work, but I don't really understand how to use it.

Not really: it shows how you'd construct a filter w/ offsets. The offset distance needs to be 1/pixel dimensions. Sphinx's is way better.
  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Ah. Well, thanks anyhow. Appreciate the effort!
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Borkus I'm curious to what you are using this for? Are you despeckling something or what is going on?
  Details E-Mail
Totte
Übernerd

Posts: 1460
Filters: 107
@Sphinx: I think he is making a FF based "Game of Life"
- I never expected the Spanish inquisition
  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
No, no -- not doing any cellular automata applets. I've discovered a really neat misapplication of Alien Skin Software's Blow Up plugin.

Check it out. First we need an image consisting of only black and white pixels:

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Now we rescale it to at least 1.5x and we get:

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
That's some nice filigree! But look at the outskirts of the features:

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Those blobs out lined in red are the offspring of some of those solitary pixels I needed killed. These solitary blobs are made up of the exact same configuration of grayscale pixels. Whether the blobs are white blobs on a black background, or black blobs on a white background, their repetition disrupts the wonderful irregularities that are created by a thriving ecosystem of pixels. THEY MUST BE DESTROYED!!!

So let's return to that fist image. We apply Sphinx's filter once, invert the image, apply the filter again, invert and we get:

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
And upsample it:

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Much better!

Now, I'm seeing that there are certain configurations of pixels that resist the transition to filigree. Here's a zoomed-in view of the culprits.

  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Sphinx, could I beseech you to re-write the filter to find and erase those offenders?

If that's too much work, can you write a revision that erases the following:

XXX XXXX
X0X X00X
X0X XXXX
XXX

And it would be lovely to have the filter find all of the solitary pixel/pixel blocks in a single pass (that is, in one application of the filter).

But really, the filter as it exists now is good enough -- certainly it cuts down by several orders of magnitude the micro-management of removing details! Thanks again!
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Sphinx, you might just number all the 8 adjacent pixels and wire them into on/off controls - that would make it generalized and less specific. Like so:

8 1 2
7 X 3
6 5 4

Then it could be a generic pixel adjacency seek and destroy component smile:D
You could do all sorts of stuff with that: seek and destroy horizontal or diagonal lines for example.

Borkus: have you used Perfectum, by Redfield? I also does some neat effects, similar to the alien skin filter. Works great for smoothing out JPEG badness.
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Quote
Totte wrote:
@Sphinx: I think he is making a FF based "Game of Life"


Actually, ThreeDee made one of those already. (Using v1.0 components, I might add)
  Details E-Mail
Borkus McJorkus
Posts: 45
Filters: 14
Quote

CorvusCroax wrote:
Borkus: have you used Perfectum, by Redfield?


Yes, I really like Perfectum. But its results are generally wispy -- and what I'm doing with Blow Up is more... chunky?
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,533 Posts
+38 new in 30 days!

15,348 Topics
+73 new in year!

Create an Account

Online Users Last minute:

32 unregistered users.