Giter Site home page Giter Site logo

imganalysis.jl's Introduction

ImgAnalysis.jl

# 1 Installation

julia> import Pkg
julia> Pkg.add(url="https://github.com/yctai1994/ImgAnalysis.jl.git")

Optionally, you can also install

julia> Pkg.add("CairoMakie")

# 2 Preprocess the image

# Directly preprocess the image and save it to a new image file

using ImgAnalysis
preprocess(
    "$fname.jpg";
    ifsave=true, fname="$fname-processed.jpg",
    height_order=3, width_order=3
)

# 3 Clustering Pixels and Find Their Area

import FileIO, ImageIO, CairoMakie, DelimitedFiles
using ImgAnalysis
  1. Import the preprocessed image and prepare the classifier.
fname  = "<img path here>" # no file extension
imgSrc = Float32.(FileIO.load("$fname.jpg"))
classifier = ImgClassifier(imgSrc;)
  1. Assign hyperparameters and compute the kernel (Gram) matrix. (The comments on the right-hand side are the alternatives if you want to avoid typing the full names of all arguments.)
set_params!(classifier;
    cluster_num      = 4,   # K  = 4,
    height_scaler    = 1.5, # γH = 1.5,
    width_scaler     = 1.5, # γW = 1.5,
    grayscale_scaler = 6.0  # γG = 6.0
)
  1. Solve the clustering.
solve!(classifier)
  1. Demo the result (in ImgAnalysis.jl.git/tmp).
demo(imgSrc, classifier.result;
     ifsave=false, fname="$fname-compare")
  1. You can find all the linked-pixel areas upon your interests using
# target_label::Int is the label of
# clustering, e.g., 1, 2, 3.
filtered_labels = count_area(classifier.result, target_label)

argmax(x -> x[3], filtered_labels)

, or you can save the clustering result to a .txt file (in ImgAnalysis.jl.git/tmp).

params = classifier.params
save_result("$fname.txt", classifier.result;
            K=params.K, P=params.Pinit,
            γH=params.γH, γW=params.γW, γG=params.γG)

imganalysis.jl's People

Contributors

brianyjtai1994 avatar yctai1994 avatar

Stargazers

 avatar

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.