julia> import Pkg
julia> Pkg.add(url="https://github.com/yctai1994/ImgAnalysis.jl.git")
Optionally, you can also install
julia> Pkg.add("CairoMakie")
using ImgAnalysis
preprocess(
"$fname.jpg";
ifsave=true, fname="$fname-processed.jpg",
height_order=3, width_order=3
)
import FileIO, ImageIO, CairoMakie, DelimitedFiles
using ImgAnalysis
- Import the preprocessed image and prepare the
classifier
.
fname = "<img path here>" # no file extension
imgSrc = Float32.(FileIO.load("$fname.jpg"))
classifier = ImgClassifier(imgSrc;)
- 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
)
- Solve the clustering.
solve!(classifier)
- Demo the result (in
ImgAnalysis.jl.git/tmp
).
demo(imgSrc, classifier.result;
ifsave=false, fname="$fname-compare")
- 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)