juliaImg2npImg now return 2 color np img
This commit is contained in:
@@ -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
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user