libmir / dcv Goto Github PK
View Code? Open in Web Editor NEWComputer Vision Library for D Programming Language
Home Page: http://dcv.dlang.io/
License: Boost Software License 1.0
Computer Vision Library for D Programming Language
Home Page: http://dcv.dlang.io/
License: Boost Software License 1.0
Implement basic raster shape drawing for dcv.plot module.
Sources:
https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm
Possible variants:
nothrow @nogc
layer should be presented. OOP API should be optional or removed. Advantage: number of users and contributors are limited only by langauge bindings like Python, Julia, Ruby, Rust, and Go (yes, we can build libraries for Rust and Go ๐ I think it is better way to move forward with D ). A professional project that can be live during many-many years.Library for D in 99% cases is useless as general purpose library. Library written in D is a library for D, which can be used in other languages like a common C library.
For example void write_png(Writer stream, long w, long h, in ubyte[] data, long tgt_chans = 0)
from image formats can be used.
@ljubobratovicrelja You may want to ask @wilzbach to move DCV site :-)
Both are single line functions. See #33
normalized
single line too.
scaled
is not used if am not wrong. User can do slice[] *= scalar
/slice[] += scalar
or use ndEach
if both *
and +
are required.
dcv is amazing proof of concept for ndslice. Please add notes, that it is based on ndslice in the future forum announce and dcv readme.
the site is broken on android, it constantly just redirects to itself
from https://twitter.com/WebFreak001/status/765138108417474560
Image path strings have the ?raw=true
metadata:
https://ljubobratovicrelja.github.io/dcv/?loc=example_filter.html
Won't work
# ./video -f ../data/centaur_1.mpg
[mpegvideo @ 0xd9d320] Estimating duration from bitrate, this may be inaccurate
core.exception.AssertError@../../source/dcv/core/image.d(171): Assertion failure
aSlice[i]
requires 1 addition and 1 multiplication
aSlice[i, j]
requires 2 additions and 2 multiplications
90% of algorithm can be iterated using ndslice.algorithm (ndMap, ndReduce). Other 10% can use front!d
, popFront!d
methods
From RHT module:
/// Run RHT using non-zero points in image as edge points.
auto opCall(T)(Slice!(2, T*) image)
{
Point[] points;
foreach (y; 0 .. image.length!0)
foreach (x; 0 .. image.length!1)
{
if (image[y, x] > 0)
{
points ~= Point(cast(int)x, cast(int)y);
}
}
return this.opCall(image, points);
}
This example has 2 issue. The first is slow indexing. The second is ~=
concatenation, which changes complexity from O(n)
to O(n^2)
.
ldmd2
should be used with DUB, not ldc2
as!aType.slice.asImage
allocates without reason, bacause asImage allocates data anyway. asImage is uses data too. In addition, it should be something like toImage
.
I have got a lot of images in jpg format with black background. Is it's possible to find background and remove it (make transparent) with current version of DCV? PNG as output would be enough for me (in ideally wepb, but D do not have native encoder/decoder :( )
If not DCV, maybe there is any better tools for this task?
According to libmir/dcompute#7 upcoming openCL can be used for thread and synchronization management instead of druntime for CPU (not only for GPUs) and kernels can be optimized as good as common CPU code. So the idea is to drop support for DMD. The benefits:
nothrow @nogc
parallellism using upcoming dcompute.It is very slow (zip is the same)
Non-maxima suppression implementation is faulty.
See RHT example canny image:
https://github.com/ljubobratovicrelja/dcv/blob/master/examples/rht/result/canny.png
As soon as mir.image be implemented, we will have good conversions between all formats we use. ranged
is functions that stretch color domain for each channel. If you apply this for not very contrast image, it will make it more contrast. This implicit filter functionality is bad practice.
Many separable filters are used with fixed size, e.g. 2, 3, 4, 5. It can be done with static foreach.
It seem your naming conventions and abbreviations does not give a good experience IMO. Long naming might be better in some cases.
Like;
Image image = imread("/path/to/image.png"); // read an image from filesystem.
auto slice = image.sliced; // slice image data (calls std.experimental.ndslice.slice.sliced on image data)
slice
.asType!float[0..$, 0..$, 1] // convert slice data to float, and take the green channel only.
.conv!symmetric(sobel!float(GradientDirection.DIR_X)) // convolve image with horizontal Sobel kernel.
.byElement
.ranged(0, 255).array.sliced(slice.shape[0..2]) // scale values to fit the range between the 0 and 255
.imshow("Sobel derivatives"); // preview changes on screen.
waitKey();
some thing like readImage(), showImage()
.
You tend to mix them, like there is byElement()
which is not consistent with imread(), imshow()
etc.
@ljubobratovicrelja Are you interesting to move DCV to libmir project? Copyright, the project name are preserved as is.
Does existing or future dcv requires ML algorithms? If yes, please open an issue in https://github.com/libmir/mir/issues . Most of ML can be split to data preparation and other computations. Other computations_ may be added to Mir as building blocks for ML algorithms in dcv.
@9il unit tests are failing - I'm not quite sure what has changed in mir.ndslice.slice.slice
, could you help out?
Please add tests for LDC and different compiler versions. Also windows testing is very important for users.
See also how it is done for Mir:
https://github.com/libmir/mir/blob/master/circle.yml
https://github.com/libmir/mir/blob/master/.travis.yml
https://github.com/libmir/mir/blob/master/appveyor.yml
Remove README.md content from examples in the project - not to have doubled example content that requires updating and syncing.
Proposition by @9il, started in #62.
Do we really need Image type? Why?
As said in the description of the module in docs it is designed mainly to help with image I/O, but also to hold additional image metadata. Since it's data type is defined in runtime, it allows reading of unknown image format. Since Slice format is statically defined, we would have to expect certain image format when reading it, and if read image is not of expected format, we'd have to convert it. Also, Image contains additional metadata, e.g. color format (HSV, YUV, RGB etc.). And, in future Image should hold EXIF metadata.
Pipeline in DCV should be:
Image = dcv.core.image.Image
Slice = mir.ndslice.slice.Slice
LoadImage(path) --> dcv.core.image.Image
InspectAndAdoptImageFormat(Image) --> Slice
Processing(Slice) --> Slice
PackSliceToImage(Slice) --> Image
SaveImage(Image, path)
Long story short, we need image container with runtime defined data type, and additional image related metadata.
This is scripting language idioms. They are not good for D.
If you have processing, then you work with one, two, maximum three formats for processing.
They should have their own CT instantiations because performance reasons.
Then, when you want to save something, you can just call a function which accepts Slice, Metadata, and optionally RT/CT format.
The last one issue os reading. Yes, when we read something, the image format is unknown. But, as was said above, only beforehand image types are interesting. So, a user or library should define mapping, for example:
It is not possible to eliminate this mapping. But rather hiding it in different classes implementations it is better how have an explicit way to do it and library helpers if required.
Please avoid any usage of classes (except already existing D libs, which can be replaced in future). Even async I/O can be performed without classes. D users like it because they are familiar with OOP. But this is bad practice for D. Structural programming is proper way to move forward with D.
Equal is really weird shortcut for Equalize in Dlang
As discussed in #48, maybe we should start planning on how to enrich the image I/O package of the library. Imageformats library is good (especially because it is purely written in D), but format coverage is poor (especially for encoders).
So first idea is to build minimal bindings (or use existing ones) to popular C libraries:
Some people already translated some of the popular encoder/decoders to D. I feel that's not that easy to do, and I'd personally much more like to focus on the DCV's core, but if we decide to take this step, no problem.
@henrygouk suggested we could use ffmpeg to encode/decode image formats. This also seems like a great choice since lot of formats are supported, and ffmpeg-d is already a dependency.
There was also discussion that users should be free to use 3rd party libraries for image I/O with DCV. I believe this is already achievable in DCV - e.g. if user is working with gtkd, and dcv:core, he/she can load pixbuf from file, then slice it's data and work along with dcv algorithms. So, I believe we're OK here, except maybe we should make an example on this topic to show it to people.
Also we discussed if image io should be separated from video - in #48 we defined dcv:io
sub-package, where we could have defined dcv:ioimage
, and dcv:iovideo
. If we decide to go with first option (bind C libs), I really think we should do this since it would be heavy loaded with C libs.
Any comment is welcome.
A user may want to use this library only for CV algorithms. Library should not force a user to install any C libraries.
Looks like DCV may be splitt to
Current library looks like it is oriented for the end user. Comparing with Python, it is better practice for D to have an API, which can be used to build extended functionality, e.g. to be used in other libraries and cross-platform products.
glfw can be used for imshow directly
It can be replaced with single template which calls ndslice.algorithm and colour transformations from upcoming Phobos color
module.
Dub: http://code.dlang.org/packages/color
Git: https://github.com/TurkeyMan/color
Colour thread at forum: https://forum.dlang.org/thread/[email protected]
In addition, color transformation should use 2D representation where color is packed in the last dimension. This will optimise iteration.
When I resize an image in GIMP, I got completely different result.
For example, in DCV I do this:
// w == 3; The image is a 2MP RGBA photo.
auto slice = image.sliced;
writeln(slice[0, 0, 0 .. $]);
auto thumbnail = slice.resize!linear([w, w]);
auto rgb = thumbnail[0 .. $, 0 .. $, 0 .. 3];
writeln(rgb);
and I got this:
[196, 198, 249, 255]
[[[196, 198, 249], [156, 166, 189], [82, 59, 100]], [[231, 163, 178], [35, 39, 34], [104, 98, 122]], [[141, 120, 119], [26, 36, 44], [169, 141, 130]]]
The first pixel of the downscaled image is the same as the first pixel of original image.
This is not what I expect.
The common pattern for dcv is aSlice.byElement.rangedFunction
. It has few performance issues:
So, you may want to swtich from dcv.core.algorithm
to ndslice.algorithm
.
The documentation for ndslice.algorithm
can be found here. ndslice.algorithm
is currently available only in Mir.
So, switching to Mir is good option. It is providing recent and upcoming ndslice changes for both DMD and LDC. Also, mir will migrate to Phobos's ndslice after 2-3 DMD releases and will provide deprecation imports with aliasing. ndslice,algorithm
is not the last module in ndslice package, also ndslice.concatenation
will be added this year.
Please ask me questions if you have any.
HI again, cv library always is complex, so i wanna join to develop, but some internals hard to understand, i think we need provide some debug output (to help bug reports) in "debug build" or some version definition
like USE_DCV_DEBUG
Nicholas Wilson merged dcompute to libmir organization. It is not ready yet, but we can figure out what DCV algorithms can be expressed as GPU kernels, and what GPU subroutines required in DCV should be implemented in Mir.
dlang/phobos#4780 will be available for 2.072. As soon as LDC will have it too, the code can be simplified.
Benefits:
std.color can be improved to support DCV if it is required. In addition, we can add fastmath to std.color if we want.
I have reviewed a set of files. We still have std.range
and std.array
are used frequently. The reasons to remove them:
ndslice does not require std.range and incorporates its funcitonality.
Maybe few cases with std.array can be still useful. But most of them are used for slice allocation
dub.json
should not import examples, but in unittest configuration.
Also, according to the #25, dcv should not depend on C libraries. Mir will have matrix inversion: that will allow to exclude scid (C LAPACK) dependency.
Implement most common morphological operations on images - dilation, erosion, opening, closing
Sources:
https://en.wikipedia.org/wiki/Opening_(morphology)
https://en.wikipedia.org/wiki/Dilation_(morphology)
https://en.wikipedia.org/wiki/Erosion_(morphology)
deprecate("pelase use 'yourSlice.as!aType.slice' instead")
for example
Implement histogram equalization.
Optional: Implement Otsu's thresholding method.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.