Implement 2d and 3d histograms of images. Support gray and colored. Include support for plotting and some predefined layouts.
Main purpose is to have a view to the color sitribution to check the quality of photos. And to have a reasonable sized window and not a little stamp.
Copy ImageHistogram.jl and/or ImageHistogramTest.jl into the load path of julia. Alternatively extend julia's load path to contain the directory the module files are located.
ImageHistogramTest contains functions trying to plot 3D using Plots.
using Images, TestImages ; reload("ImageHistogram") ; img_col256 = testimage("lena_color_256");
ihR,ihG,ihB = ImageHistogramTest.imhistogramRGB(img_col256);
ihgray = ImageHistogramTest.imhistogramGray(img_col256);
plot(ihgray, color=:lightgray, w=3, line=:sticks)
plot(ihR, line=:red, w=2)
plot_red = plot(ihR, line=:red, w=2); plot_green = plot(ihG, line=:green, w=2); plot_blue = plot(ihB, line=:blue, w=2); plot_Gray = plot(ihgray, line=:lightgray, w=2);
using Images, TestImages ; reload("ImageHistogramTest") ; img_col256 = testimage("mandril_color");
ihR,ihG,ihB = ImageHistogramTest.imhistogramRGB(img_col256);
ihgray = ImageHistogramTest.imhistogramGray(img_col256);
ImageHistogramTest.plot_imhi(ihR_cooked=ihR, ihG_cooked=ihG, ihB_cooked=ihB,how=1,bg=1)
ImageHistogramTest.plot_imhi(ihR_cooked=ihR, ihG_cooked=ihG, ihB_cooked=ihB,how=4,bg=1)
ImageHistogramTest.plot_imhi(ihGray_cooked=ihgray,ihR_cooked=ihR, ihG_cooked=ihG, ihB_cooked=ihB,how=3,bg=1)
ImageHistogramTest.plot_imhi_GrayRGB(img_col256)
ImageHistogramTest.plot_imhi_GrayRGB(img_col256, how=3, bg=0)
With the new Gnuplot.jl verion 0.2.0, doing splot based stuff is easier, and works well.
using Gnuplot;
using Images, TestImages ; reload("ImageHistogram") ; img_col256 = testimage("lena_color_512");
redv, greenv,bluev, colv = ImageHistogramTest.imhistogramRGB3d_new2(img_col256);
redv=redv*255.0; greenv=greenv*255.0; bluev=bluev*255.0;
gen_pcv(cv24_a)=(pcv24=zeros(length(cv24_a));for i = 1:endof(cv24_a); pcv24[i]=cv24_a[i].color; end;return pcv24)
@gsp(redv[1:10:end],greenv[1:10:end],bluev[1:10:end],gen_pcv(colv[1:10:end]),"with points pt 13 ps 0.7 lc rgb variable", xrange=(0,255), yrange=(0,255), zrange=(0,255), xlabel="red", ylabel="green", zlabel="blue", "set border -1", "set tics in mirror", "set grid", "set zticks out mirror", "set grid ztics", "set xyplane at 0.0")
After hitting the return-key, be patient for a few seconds. Especially if you use the full range of the color arrays. Each has a size of 148279.
Doing the same with "mandril_color" has much less colors and color spots than smooth distribution.
With GR as backend. Ensure to feed scatter3d() with less than 3000 - 4000 points per color. It is too slow and it may die.
using Plots;
using Images, TestImages ; reload("ImageHistogram") ; img_col256 = testimage("lena_color_512");
redv, greenv,bluev, colv = ImageHistogramTest.imhistogramRGB3d_new2(img_col256);
redv=redv*255.0; greenv=greenv*255.0; bluev=bluev*255.0;
scatter3d(redv[1:50:end], greenv[1:50:end], bluev[1:50:end],color=colv[1:50:end], markerstrokewidth=0, markersize=2,marker=:circle) # set border of marker symbol to zero with 'markerstrokewidth=0'
scatter3d(redv[1:11:end], greenv[1:11:end], bluev[1:11:end],color=colv[1:11:end], ms=0.1, msw=0, xlims=(0,255),ylims=(0,255),bg=:black, cam=(85,80)) # set the camera angle to see the plot in this case from above
or just call
ImageHistogramTest.plot_imhi_3D(img_col256); # with default range_step = 50, i.e. just take each 50s point
ImageHistogramTest.plot_imhi_3D(img_col256, range_step = 30); #
ImageHistogramTest.plot_imhi_3D(img_col256, range_step = 1); # take each color value; requires much mem; on Windows best after a re-boot
to create a draft 3D histogram.
Hints for improvements are welcome via tickets, pull requests, ...
PS: My coding style uses ';' at line ends by intention. I use copy-n-paste from/to REPL and want quiet exec.
05/13/2018
almost 3 years ago
22 commits