Skip to content

yctai1994/ImgAnalysis.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)