MoonBit-native lightweight image processing and basic computer vision algorithms.
powershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://cli.moonbitlang.com/install/powershell.ps1 | iex"
moon versioncd $env:USERPROFILE\Desktop
moon new MoonVisionExternalCheck --user LocalCheck --name MoonVisionExternalCheck
cd MoonVisionExternalCheck
moon add PingGuoMiaoMiao/MoonVision@0.2.5import {
"PingGuoMiaoMiao/MoonVision/image",
"PingGuoMiaoMiao/MoonVision/ops",
"PingGuoMiaoMiao/MoonVision/filter",
"PingGuoMiaoMiao/MoonVision/edge",
"PingGuoMiaoMiao/MoonVision/components",
"PingGuoMiaoMiao/MoonVision/export",
}
pkgtype(kind: "executable")fn main {
let gray = try! @image.gray_from_array(
4,
4,
[
b'\x00', b'\x00', b'\xff', b'\xff',
b'\x00', b'\x40', b'\xc0', b'\xff',
b'\x00', b'\x40', b'\xc0', b'\xff',
b'\x00', b'\x00', b'\xff', b'\xff',
],
)
let binary = try! @ops.threshold(gray, 100)
let blurred = try! @filter.gaussian_blur(gray, radius=1)
let canny = try! @edge.canny_edges(blurred, 32, 96)
let components = try! @components.connected_components(binary, min_area=1)
let png = @export.encode_gray_png(canny)
println(
"external-ok width=\{gray.width()}, height=\{gray.height()}, components=\{components.length()}, png_bytes=\{png.length()}"
)
}moon check
moon build
moon run cmd/mainexternal-ok width=4, height=4, components=1, png_bytes=80cd $env:USERPROFILE\Desktop\MoonVision
moon check -d
moon check --warn-list +73
moon build
moon test
moon fmt --check
moon info
moon run src/demo/object_counting
moon run src/demo/edge_detection
moon run src/demo/document_enhancementpowershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://cli.moonbitlang.com/install/powershell.ps1 | iex"
moon versionmoon 0.1.20260803 (c19f78e 2026-08-03)cd $env:USERPROFILE\Desktop
moon new MoonVisionExternalCheck --user LocalCheck --name MoonVisionExternalCheck
cd MoonVisionExternalCheck
moon add PingGuoMiaoMiao/MoonVision@0.2.5import {
"PingGuoMiaoMiao/MoonVision/image",
"PingGuoMiaoMiao/MoonVision/ops",
"PingGuoMiaoMiao/MoonVision/filter",
"PingGuoMiaoMiao/MoonVision/edge",
"PingGuoMiaoMiao/MoonVision/components",
"PingGuoMiaoMiao/MoonVision/export",
}
pkgtype(kind: "executable")fn main {
let gray = try! @image.gray_from_array(
4,
4,
[
b'\x00', b'\x00', b'\xff', b'\xff',
b'\x00', b'\x40', b'\xc0', b'\xff',
b'\x00', b'\x40', b'\xc0', b'\xff',
b'\x00', b'\x00', b'\xff', b'\xff',
],
)
let binary = try! @ops.threshold(gray, 100)
let blurred = try! @filter.gaussian_blur(gray, radius=1)
let canny = try! @edge.canny_edges(blurred, 32, 96)
let components = try! @components.connected_components(binary, min_area=1)
let png = @export.encode_gray_png(canny)
println(
"external-ok width=\{gray.width()}, height=\{gray.height()}, components=\{components.length()}, png_bytes=\{png.length()}"
)
}moon check
moon build
moon run cmd/mainexternal-ok width=4, height=4, components=1, png_bytes=80cd $env:USERPROFILE\Desktop\MoonVision
moon check -d
moon check --warn-list +73
moon build
moon test
moon fmt --check
moon info
moon run src/demo/object_counting
moon run src/demo/edge_detection
moon run src/demo/document_enhancementsrc/
image/ GrayImage, RgbImage, pixel access, gray transforms
ops/ grayscale, threshold, otsu, adaptive threshold, brightness, contrast
histogram/ grayscale histograms and histogram equalization
filter/ convolution, box blur, gaussian blur, sharpen, median blur
edge/ sobel, gradient magnitude, canny, hough lines
morphology/ binary morphology operators and derived morphology
components/ connected components, contours, distance transform, and bounding boxes
match/ grayscale template matching
export/ PNG encoding, SVG overlays, HTML reports
demo_support/ demo-only file writing helpers
demo/ runnable demo packageslet rgb = try! @image.rgb(4, 4)
let gray = try! @ops.grayscale(rgb)
let binary = try! @ops.otsu_threshold(gray)
let adaptive = try! @ops.adaptive_threshold_mean(gray, 5, 7)
let denoised = try! @filter.median_blur(gray, radius=1)
let blurred = try! @filter.gaussian_blur(gray, radius=1)
let resized = try! @image.resize_nearest(gray, 8, 8)
let smooth_resized = try! @image.resize_bilinear(gray, 8, 8)
let rotated = try! @image.rotate90_cw(gray)
let equalized = try! @histogram.equalize_histogram(gray)
let edges = try! @edge.gradient_magnitude(blurred)
let canny = try! @edge.canny_edges(blurred, 48, 96)
let lines = try! @edge.hough_lines(canny, vote_threshold=4, max_lines=8)
let blobs = try! @components.connected_components(binary, min_area=4)
let distances = try! @components.distance_transform_manhattan(binary)
let contours = try! @components.find_contours(binary)
let first_kind = @components.contour_kind(contours[0])
let first_parent = @components.contour_parent_index(contours[0])
let simplified = @components.approx_contour(contours[0], 1.0)
let hull = @components.convex_hull(contours[0])
let rect = @components.min_area_rect(contours[0])
let circularity = @components.contour_circularity(contours[0])
let solidity = @components.contour_solidity(contours[0])
let best_match = try! @match.match_template_sad(gray, gray)
ignore(adaptive)
ignore(denoised)
ignore(resized)
ignore(smooth_resized)
ignore(rotated)
ignore(equalized)
ignore(edges)
ignore(canny)
ignore(lines)
ignore(blobs)
ignore(distances)
ignore(contours)
ignore(first_kind)
ignore(first_parent)
ignore(simplified)
ignore(hull)
ignore(rect)
ignore(circularity)
ignore(solidity)
ignore(best_match)let png = @export.encode_gray_png(binary)
ignore(png)let overlay = @export.svg_bounding_boxes(
binary.width(),
binary.height(),
blobs,
)
ignore(overlay)let input = try! @image.rgb_from_png_bytes(png_bytes)
ignore(input)moon run src/demo/object_countingmoon run src/demo/edge_detectionmoon run src/demo/document_enhancementpowershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -ForceRerunpowershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -SampleFolders 346powershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -SampleFolders 346 -ExcludeRenameCopiespowershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -MaxImages 3powershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -SampleFolders 346powershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -SampleFolders 346 -ExcludeRenameCopiespowershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -MaxImages 3powershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -ForceRerunmoon check -d
moon check --warn-list +73
moon build
moon test
moon fmt --check
moon infomoon run src/demo/object_counting
moon run src/demo/edge_detection
moon run src/demo/document_enhancementpowershell -NoProfile -ExecutionPolicy Bypass -File tools/run_labeled_bacteria_review.ps1 -SampleFolders 346 -ExcludeRenameCopiesMoonBit-native lightweight image processing and basic computer vision algorithms.