Changes

Jump to: navigation, search

BLAStoise

313 bytes added, 23:00, 12 February 2017
no edit summary
----
'''<h4>Oil Painting By Sallie J.'''</h4>
This program converts a regular image into a stylized oil painting, it uses OpenCV. The painting algorithm depends on the brush size and colour intensity. The program takes three command line arguments: int for brush size, int for intensity and file name of an image. Upon finishing, the program produces the original image along with the oil paint version and the total time required in seconds.
However there have been some changes to make testing and profiling slightly easier. (Mainly changes are putting the for-loop logic into a function outside of the main and modifying for command line arguments instead of hard coding values.)
'''<h5>Running the program'''</h5>
To compile the program on Linux you must download the OpenCV library and then create a makefile that will create the executable OilPaint.exe. To compile the program in visual studio you will need to set project properties for OpenCV through setting the C/C++ Additional Include Directories, Linker Additional Library Directories and Input Additional Dependencies (opencv_world320d.lib).
[[Media: OilPaint.zip]]
This zip file contains a make file and the cpp file. To compile on Linux alter the makefile.
Run the executable with the arguments 5 (brush size), 20 (colour intensity), filename.format (including file format)
Output: $ cmake -DCMAKE_CXX_FLAGS=-pg =DCMAKE_EXE_LINKER_FLAGS=-pg -DCMAKE_SHARED_LINKER_FLAGS=-pg -pg . $ make $ ./OilPaint 5 20 filename.fileformat
[[File<h6>Output:t2.jpg|600px]] [[File:OilVersion-t2.jpg|600px]] </h6>
[[File:t2.jpg|550px]][[File:OilVersion-t2.jpg|550px]]  <h6>gprof Output:</h6>
Flat profile:
Each sample counts as 0.01 seconds.
... (there are a lot of other calls to the library that did not significantly affect the profiling)
vs <h6>Visual Studio Performance profiler Output:</h6>
[[File:VSPROFILE.png]]
The time required for the program depends largely on the file size being converted. Around 5 seconds for a 50KB image and 100 seconds for a 1MB image. It depends on the brush size and intensity levels as well.
'''<h5>Analysis'''</h5>
The profiling revealed that 80-99% of the processing time is spent in the paint function where the for-loop logic is located. Within that 99% the program spends roughly 2/3 of its time reading accessing data through the "at" function of the OpenCV Mat class (n-dimensional dense array class). The other 1/3 is spent on direct access through OpenCV’s Vec class (short numerical vectors). The for-loop is structured divides the picture up based on brush size. Then it finds the colour for each pixel in that section. Finally, it then averages the intensity to produce the final colour of that group of pixels. This is what makes this program ideal for parallelizing, because each iteration of this for-loop is calculating the final colours for each pixel. (SIMD type of process, the single instruction is to find the final colour and the multiple data is the pixels.)
23
edits

Navigation menu