Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
20
Task/Grayscale-image/Julia/grayscale-image-1.julia
Normal file
20
Task/Grayscale-image/Julia/grayscale-image-1.julia
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using Color, Images, FixedPointNumbers
|
||||
|
||||
const M_RGB_Y = reshape(Color.M_RGB_XYZ[2,:], 3)
|
||||
|
||||
function rgb2gray(img::Image)
|
||||
g = red(img)*M_RGB_Y[1] + green(img)*M_RGB_Y[2] + blue(img)*M_RGB_Y[3]
|
||||
g = clamp(g, 0.0, 1.0)
|
||||
return grayim(g)
|
||||
end
|
||||
|
||||
function gray2rgb(img::Image)
|
||||
colorspace(img) == "Gray" || return img
|
||||
g = map((x)->RGB{Ufixed8}(x, x, x), img.data)
|
||||
return Image(g, spatialorder=spatialorder(img))
|
||||
end
|
||||
|
||||
ima = imread("grayscale_image_color.png")
|
||||
imb = rgb2gray(ima)
|
||||
imc = gray2rgb(imb)
|
||||
imwrite(imc, "grayscale_image_rc.png")
|
||||
5
Task/Grayscale-image/Julia/grayscale-image-2.julia
Normal file
5
Task/Grayscale-image/Julia/grayscale-image-2.julia
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
using Color, Images, FixedPointNumbers
|
||||
|
||||
ima = imread("grayscale_image_color.png")
|
||||
imb = convert(Image{Gray{Ufixed8}}, ima)
|
||||
imwrite(imb, "grayscale_image_julia.png")
|
||||
Loading…
Add table
Add a link
Reference in a new issue