Code Monkey home page Code Monkey logo

Comments (21)

rafaqz avatar rafaqz commented on September 10, 2024 1

I can do "random cluster nearest neighbor" :))

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024 1

@mkborregaard I think so - exportasciigrid is something I've done before (readasc as well) so I'll dig it up.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

Do you want push access to the org @rafaqz ?

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

Sure. Thanks.

How do you feel about an ImageMorphology.jl dep? It has the label and feature distance methods we need for nearest neighbor algs.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

Given that this is an end-user-facing package rather than a base package I don't see any issues with taking on deps. It's not exactly lightweight though - does NearestNeighbors.jl not do the trick? - let's continue that discussion under #14

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

@mkborregaard just tried pushing a perlin branch but was denied 🥺

Can someone give me push access?

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

Did you accept the membership invite?

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

You didn't, it seems, it's still listed as "pending"

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

Oops sorry, my github message feed is insane these days

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

What's missing in addition to the algorithms?

  • classifyarra0
  • blendarrays
  • blendclusterarray
  • meanofcluster
  • exportasciigrid [wontfix]

and that's it, right?

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

ascii in #26 -- this is exportasciigrid

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

So the last algo remaining is not the most friendly, because we need a sort of image segmentation code for it to work.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

is that ndimage.measurements.label?
I worked around that function call in _clusterMean but looking at it I don't think I did it right, so I'll just need to check that code again.

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

It can be solved with a heuristic as a temporary solution. That's nothing more than a constrained label propagation, and this tends to converge in a few iteration. I can try this and see if that performs well.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

Nice. Yeah I thought it could essentially be done single-pass but maybe I'm not understanding the full complexity of the issue

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

ImageMorphology.jl has this. Maybe just doing that PR to generalise it is less work.

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

So there is very little to it in ImageMorphology... except it uses traits like coords_spatial from ImageCore.jl. Again not even image related, but lots of image related deps.

It looks like we have to abstract everything not image related out of the Images.jl ecosystem at some stage. I think it's not much work technically and it's even their long-term intention, but getting all the PRs through and package registrations would be a lot of work. But ...someone has to do it some day - these methods are in Numpy, not some python image package.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

Update: I wasn't understanding the full complexity of the issue.
Anyway, pushing on ImageMorphology sounds like a good idea, if that org catches the ball and start running with it some of us could possibly help? Let's see how responsive they are.

from neutrallandscapes.jl.

rafaqz avatar rafaqz commented on September 10, 2024

I could do most of it honestly, they are really small changes. The main issue is getting agreement on moving the traits out of ImageCore.jl and to somewhere without all those depsendencies.

from neutrallandscapes.jl.

mkborregaard avatar mkborregaard commented on September 10, 2024

I think the ImageMorphology is the right way to go honestly and it sounds like they are amenable to it. Honestly having them split and then Raf's fast code in Stencils would be a really awesome thing for the ecosystem.
Just because I'm stupid I did find it fun to try and implement a label function myself. I think I succeeded (and that it's OK efficient) - I could put that in a PR for now?

function _label(mat)
    rook = ((1, 0), (0, 1))
    m, n = size(mat)
    (m >= 3 && n >= 3) || error("The label algorithm requires the landscape to be at least 3 cells in each direction")
    
    # initialize objects and fill corners of ret
    ret = zeros(Int, m, n)
    clusters = Dict{Int, Int}()
    label = 0

    # run through the matrix and make clusters
    for j in axes(mat, 2), i in axes(mat, 1)
        same = [i - n[1] > 0 && j - n[2] > 0 && mat[i - n[1], j - n[2]] == mat[i, j] for n in rook]
        if count(same) == 0
            ret[i, j] = label += 1
            clusters[label] = label
        else
            vals = [ret[i - n[1], j - n[2]] for n in rook[same]]
            mi = minimum(vals)
            for v in vals
                clusters[v] = mi
            end
            ret[i, j] = mi
        end
    end
    
    # merge adjacent clusters with same value
    ncl = 0
    for i in eachindex(ret)
        ret[i] = _getval(clusters, ret[i])
        ncl = max(ncl, ret[i])
    end
    ncl, ret
end

function _getval(clusters, val)
    while true
        val2 = clusters[val]
        val2 == val && return val
        val = val2
    end
end

An example use

a = rand(DistanceGradient(rand(1:100, 3)), 10, 10)
b = classify!(copy(a), ones(4))
nc, c = _label(b)
plot(heatmap(a), heatmap(b), heatmap(c, fillcolor = :picasso), size = (1400, 400), layout = (1,3))

Two example runs
_label
_label2

from neutrallandscapes.jl.

tpoisot avatar tpoisot commented on September 10, 2024

that looks like it works - let's PR this and if the ImageMorpho split happens we'll replace it?

from neutrallandscapes.jl.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.