juliaImg2npImg now return 2 color np img

This commit is contained in:
ton
2023-04-03 07:26:17 +07:00
parent 8cb66108cc
commit 542ba7be65
4 changed files with 81 additions and 10 deletions

Binary file not shown.

View File

@@ -2,7 +2,7 @@
julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "1efd94b709fc54ef0775a14844517db423b83354"
project_hash = "51be691adf4b3e9b6bb3e974565a5e4b688dfd74"
[[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"]
@@ -44,6 +44,11 @@ version = "0.4.6"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
[[deps.BitFlags]]
git-tree-sha1 = "43b1a4a8f797c1cddadf60499a8a077d4af2cd2d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.7"
[[deps.CEnum]]
git-tree-sha1 = "eb4cb44a499229b3b8426dcfb5dd85333951ff90"
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
@@ -73,6 +78,12 @@ git-tree-sha1 = "7ebbd653f74504447f1c33b91cd706a69a1b189f"
uuid = "aaaa29a8-35af-508c-8bc3-b662a17a0fe5"
version = "0.14.4"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "9c209fb7536406834aa938fb149964b985de6c83"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.1"
[[deps.ColorSchemes]]
deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "Random", "SnoopPrecompile"]
git-tree-sha1 = "aa3edc8f8dea6cbfa176ee12f7c2fc82f0608ed3"
@@ -222,6 +233,12 @@ git-tree-sha1 = "1cf1d7dcb4bc32d7b4a5add4232db3750c27ecb4"
uuid = "86223c79-3864-5bf0-83f7-82e725a168b6"
version = "1.8.0"
[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "Dates", "IniFile", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
git-tree-sha1 = "37e4657cd56b11abe3d10cd4a1ec5fbdb4180263"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "1.7.4"
[[deps.ImageAxes]]
deps = ["AxisArrays", "ImageBase", "ImageCore", "Reexport", "SimpleTraits"]
git-tree-sha1 = "c54b581a83008dc7f292e205f4c409ab5caa0f04"
@@ -334,6 +351,11 @@ git-tree-sha1 = "5cd07aab533df5170988219191dfad0519391428"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.3"
[[deps.IniFile]]
git-tree-sha1 = "f550e6e32074c939295eb5ea6de31849ac2c9625"
uuid = "83e8ac13-25f8-5344-8a64-a9f2b223428f"
version = "0.5.1"
[[deps.IntegralArrays]]
deps = ["ColorTypes", "FixedPointNumbers", "IntervalSets"]
git-tree-sha1 = "be8e690c3973443bec584db3346ddc904d4884eb"
@@ -469,6 +491,12 @@ version = "0.3.23"
[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
[[deps.LoggingExtras]]
deps = ["Dates", "Logging"]
git-tree-sha1 = "cedb76b37bc5a6c702ade66be44f831fa23c681e"
uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36"
version = "1.0.0"
[[deps.MKL_jll]]
deps = ["Artifacts", "IntelOpenMP_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"]
git-tree-sha1 = "2ce8695e1e699b68702c03402672a69f54b8aca9"
@@ -490,6 +518,12 @@ version = "0.4.1"
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[deps.MbedTLS]]
deps = ["Dates", "MbedTLS_jll", "MozillaCACerts_jll", "Random", "Sockets"]
git-tree-sha1 = "03a9b9718f5682ecb107ac9f7308991db4ce395b"
uuid = "739be429-bea8-5141-9913-cc70e7f3736d"
version = "1.1.7"
[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
@@ -576,6 +610,18 @@ deps = ["Artifacts", "Libdl"]
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
version = "0.8.1+0"
[[deps.OpenSSL]]
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "OpenSSL_jll", "Sockets"]
git-tree-sha1 = "6503b77492fd7fcb9379bf73cd31035670e3c509"
uuid = "4d8831e6-92b7-49fb-bdf8-b643e874388c"
version = "1.3.3"
[[deps.OpenSSL_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "9ff31d101d987eb9d66bd8b176ac7c277beccd09"
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
version = "1.1.20+0"
[[deps.OpenSpecFun_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1"
@@ -727,6 +773,11 @@ uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
[[deps.SimpleBufferStream]]
git-tree-sha1 = "874e8867b33a00e784c8a7e4b60afe9e037b74e1"
uuid = "777ac1f9-54b0-4bf8-805c-2214025038e7"
version = "1.1.0"
[[deps.SimpleTraits]]
deps = ["InteractiveUtils", "MacroTools"]
git-tree-sha1 = "5d7e3f4e11935503d3ecaf7186eac40602e7d231"
@@ -859,6 +910,11 @@ git-tree-sha1 = "94f38103c984f89cf77c402f2a68dbd870f8165f"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.9.11"
[[deps.URIs]]
git-tree-sha1 = "074f993b0ca030848b897beff716d93aca60f06a"
uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"
version = "1.4.2"
[[deps.UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

View File

@@ -7,5 +7,6 @@ version = "0.1.0"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

View File

@@ -2,7 +2,7 @@ module interface
export np2juliaImage, juliaImg2npImg, imgScalePadding, url_to_image
using Images, Colors, FileIO
using Images, Colors, FileIO, HTTP
# using Luxor
using CondaPkg; CondaPkg.resolve(); CondaPkg.add_pip("pybase64"); CondaPkg.add_pip("opencv-python"); CondaPkg.add_pip("scikit-image"); CondaPkg.add_pip("Pillow"); CondaPkg.add_pip("numpy");
@@ -32,10 +32,12 @@ function url_to_image(url)
np_rgb_img = py_io.imread(url)
cv2_bgr_img = py_cv2.cvtColor(np_rgb_img, py_cv2.COLOR_RGB2BGR)
# convert cv2 img to julia img
julia_array_img = pyconvert(Array, cv2_bgr_img)
julia_rgb_img = np2juliaImage(julia_array_img)
julia_native_rgb_img = FileIO.load(url) # not converting from cv2 image
# read image directly from url not converting from cv2 image
julia_native_rgb_img = FileIO.load(HTTP.URI(url))
return julia_native_rgb_img, julia_rgb_img, cv2_bgr_img
end
@@ -73,24 +75,36 @@ np2juliaImage(img::AbstractArray) = RGB.(reinterpretc(BGR{N0f8}, PermutedDimsArr
julia> np = pyimport("numpy")
julia> img_np = np.array(img_bgr) # julia's PythonCall python-obj numpy array can be passed to PythonCall's python function
"""
function juliaImg2npImg(img_julia_RGB::Matrix{RGB{N0f8}})
function juliaImg2npReadyImg(img_julia_RGB::Matrix{RGB{N0f8}})
#TODO convert img to numpy using PythonCall
# julia image use 0-1 color range but python's opencv use 0-255 color range
img_rgb2 = img_julia_RGB .* 255;
imgch = channelview(img_rgb2);
imgch = Int.(imgch) # opencv use Integer
img_permuted = PermutedDimsArray(imgch, (2, 3, 1));
npReady_rgb_img = PermutedDimsArray(imgch, (2, 3, 1));
# build BGR image from RGB image because opencv use BGR format
img_bgr = [
img_permuted[:,:,3];;; # blue
img_permuted[:,:,2];;; # green
img_permuted[:,:,1] # red
npReady_bgr_img = [
npReady_rgb_img[:,:,3];;; # blue
npReady_rgb_img[:,:,2];;; # green
npReady_rgb_img[:,:,1] # red
];
return img_bgr
# both still are Julia array
return npReady_rgb_img, npReady_bgr_img
end
function juliaImg2npImg(img_julia_RGB::Matrix{RGB{N0f8}})
npReady_rgb_Img, npReady_bgr_Img = juliaImg2npReadyImg(img_julia_RGB)
np_rgb_img = py_np.array(npReady_rgb_Img)
np_bgr_img = py_np.array(npReady_bgr_Img)
# both are PythonCall wrapped numpy array
return np_rgb_img, np_bgr_img # opencv use np_bgr_img
end
#------------------------------------------------------------------------------------------------100
"""