Commit 58bf184aeabdcc4f18a2be8704656c1fb193bc4a

Authored by Arnaud Blanchard
1 parent e36ceac0

apps for image management

... ... @@ -8,4 +8,5 @@ subdirs(i_keyboard)
subdirs(f_max)
subdirs(f_point_of_interest)
subdirs(f_filter)
subdirs(f_gradient)
subdirs(i_d2gaussian)
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(f_conv)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(f_conv f_conv.cpp)
target_link_libraries(f_conv ${BL_LIBRARIES})
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":conv<pid>"
int main(int argc, char **argv){
blc_channel input, output, kernel;
char const *output_name, *input_name, *kernel_name;
float value;
int in_width, in_height, grad_height, grad_width, downscale=1;
int i, j, ki, kj, output_width, output_height;
int kwidth, kheight, iwidth, iheight;
blc_program_set_description("Compute convolution 2d of the data");
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_parameter(&input_name, "blc_channel-in", 1, "data to convolute ", NULL);
blc_program_add_parameter(&kernel_name, "blc_channel-in", 1, "kernel to use for convolution ", NULL);
blc_program_init(&argc, &argv, blc_quit);
input.open(input_name, BLC_CHANNEL_READ);
iwidth=input.dims[0].length;
iheight=input.dims[1].length;
blc_loop_try_add_waiting_semaphore(input.sem_new_data);
blc_loop_try_add_posting_semaphore(input.sem_ack_data);
kernel.open(kernel_name, BLC_CHANNEL_READ);
kwidth=kernel.dims[0].length;
kheight=kernel.dims[1].length;
blc_loop_try_add_waiting_semaphore(kernel.sem_new_data);
blc_loop_try_add_posting_semaphore(kernel.sem_ack_data);
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name,":conv%d", getpid()), -1, NULL);
output_width=iwidth-kwidth+1;
output_height=iheight-kheight+1;
output.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, input.format, 2, output_width, output_height);
blc_loop_try_add_waiting_semaphore(output.sem_ack_data);
blc_loop_try_add_posting_semaphore(output.sem_new_data);
output.publish();
if (input.type=='FL32'){
BLC_COMMAND_LOOP(0){
FOR(j, output_height){
FOR(i, output_width){
value=0;
FOR(kj, kheight) FOR(ki, kwidth){
value+=kernel.floats[kwidth-ki+(kheight-kj)*kwidth]*input.floats[i+ki+(kheight-kj+j)*iwidth];
}
output.floats[i+j*output_width]=value;
}
}
}
}
else if (input.type=='UIN8'){
BLC_COMMAND_LOOP(0){
FOR(j, output_height){
FOR(i, output_width){
value=0;
FOR(kj, kheight) FOR(ki, kwidth){
value+=kernel.floats[kwidth-ki+(kheight-kj)*kwidth]*input.uchars[i+ki+(kheight-kj+j)*iwidth];
}
output.uchars[i+j*output_width]=value;
}
}
}
}
return EXIT_SUCCESS;
}
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(f_gradient)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(f_gradient f_gradient.cpp)
target_link_libraries(f_gradient ${BL_LIBRARIES})
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":gradient<pid>"
#define GRAD(x,y) grad.uchars[(x)+(y)*grad_width]
/** See how to use Filter of Scharr
*
* -3 0 3
* -10 0 10
* -3 0 3 / 32
*
*/
void grad_downscale(blc_array *grad, blc_array const *input, int scale){
int i, j, id, jd, value;
float sumx, sumy;
int in_width=input->dims[0].length;
int grad_width=grad->dims[0].length;
FOR(j, grad->dims[1].length){
FOR(i, grad_width){
sumx=sumy=0;
FOR(id, scale){
FOR(jd, scale){
value=input->uchars[i+id+(j+jd)*in_width];
sumx+=value/(float)(id-scale/2+0.5);
sumy+=value/(float)(jd-scale/2+0.5);
}
}
grad->uchars[i+j*grad_width]=CLIP_UCHAR((fabs(sumx)+fabs(sumy))/scale);
}
}
}
int main(int argc, char **argv){
blc_channel input, grad;
char const *output_name, *input_name, *downscale_str;
int in_width, in_height, grad_height, grad_width, downscale=1;
int i, j, id, jd;
blc_program_set_description("Compute grtadient of the image");
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_option(&downscale_str, 'D', "downscale", "integer", "dowscale the resulting image", NULL);
blc_program_add_parameter(&input_name, "blc_channel-in", 1, "greyscale image to compute the gradient ", NULL);
blc_program_init(&argc, &argv, blc_quit);
if (downscale_str) SYSTEM_SUCCESS_CHECK(sscanf(downscale_str, "%d", &downscale), 1, "Parsing downscale '%s'", downscale_str);
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name,":gradient%d", getpid()), -1, NULL);
input.open(input_name, BLC_CHANNEL_READ);
in_width=input.dims[0].length;
in_height=input.dims[1].length;
blc_loop_try_add_waiting_semaphore(input.sem_new_data);
blc_loop_try_add_posting_semaphore(input.sem_ack_data);
grad_width=in_width-downscale;
grad_height=in_height-downscale;
/*
grad_width=in_width/downscale-1;
grad_height=in_height/downscale-1;*/
grad.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, 'Y800', 2, grad_width, grad_height);
grad.publish();
blc_loop_try_add_waiting_semaphore(grad.sem_ack_data);
blc_loop_try_add_posting_semaphore(grad.sem_new_data);
if (downscale==1)
{
BLC_COMMAND_LOOP(0){
FOR(j, grad_height){
FOR(i, grad_width){
grad.uchars[i+j*grad_width]=(abs(input.uchars[i+j*in_width]-input.uchars[i+j*in_width+1])+abs(input.uchars[i+j*in_width]-input.uchars[i+(j+1)*in_width]))/2;
}
}
}
}
else {
BLC_COMMAND_LOOP(0){
grad_downscale(&grad, &input, downscale);
}
}
return EXIT_SUCCESS;
}
... ...
... ... @@ -9,7 +9,7 @@
#define DEFAULT_OUTPUT_NAME ":point_of_interest<pid>"
#define GRAD(x,y) grad.uchars[(x)+(y)*grad_width]
#define IN(x,y) input.uchars[(x)+(y)*in_width]
/** See how to use Filter of Scharr
*
... ... @@ -21,9 +21,9 @@
int main(int argc, char **argv){
blc_channel input, output, grad;
blc_channel input, output;
char const *output_name, *input_name;
int out_width, out_height, in_width, in_height, grad_height, grad_width;
int out_width, out_height, in_width, in_height;
int i, j, sobel;
blc_program_set_description("Find a points of interest on a image");
... ... @@ -40,13 +40,8 @@ int main(int argc, char **argv){
in_width=input.dims[0].length;
in_height=input.dims[1].length;
grad_width=in_width-1;
grad_height=in_height-1;
grad.init('UIN8', 'NDEF',2, grad_width, grad_height);
out_width=grad_width-1;
out_height=grad_height-1;
out_width=in_width-1;
out_height=in_height-1;
output.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, 'Y800', 2, out_width, out_height);
output.publish();
... ... @@ -55,18 +50,11 @@ int main(int argc, char **argv){
blc_loop_try_add_posting_semaphore(output.sem_new_data);
BLC_COMMAND_LOOP(0){
FOR(j, grad_height){
FOR(i, grad_width){
grad.uchars[i+j*grad_width]=(abs(input.uchars[i+j*in_width]-input.uchars[i+j*in_width+1])+abs(input.uchars[i+j*in_width]-input.uchars[i+(j+1)*in_width]))/2;
}
}
FOR(j, out_height){
FOR(i, out_width){
sobel=-GRAD(i, j)-GRAD(i+1, j)-GRAD(i+2, j)\
-GRAD(i, j+1)+8*GRAD(i+1, j+1)-GRAD(i+2, j+1)\
-GRAD(i, j+2)-GRAD(i+1, j+2)- GRAD(i+2, j+2);
output.uchars[i+j*out_width]=(sobel > 0 && GRAD(i+1, j+1)>10) ? 255 : 0;
output.uchars[i+j*out_width]=CLIP_UCHAR((-IN(i, j)-IN(i+1, j)-IN(i+2, j)\
-IN(i, j+1)+8*IN(i+1, j+1)-IN(i+2, j+1)\
-IN(i, j+2)-IN(i+1, j+2)- IN(i+2, j+2))/8+128);
}
}
}
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(f_tee)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(f_tee f_tee.cpp)
target_link_libraries(f_tee ${BL_LIBRARIES})
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":point_of_interest<pid>"
#define IN(x,y) input.uchars[(x)+(y)*in_width]
int main(int argc, char **argv){
blc_channel input, output;
char const *output_name, *input_name;
int out_width, out_height, in_width, in_height;
int i, j, sobel;
blc_program_set_description("Find a points of interest on a image");
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_parameter(&input_name, "blc_channel-in", 1, "image from where you want to find the points of interest", NULL);
blc_program_init(&argc, &argv, blc_quit);
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name,":point_of_interest%d", getpid()), -1, NULL);
input.open(input_name, BLC_CHANNEL_READ);
blc_loop_try_add_waiting_semaphore(input.sem_new_data);
blc_loop_try_add_posting_semaphore(input.sem_ack_data);
in_width=input.dims[0].length;
in_height=input.dims[1].length;
out_width=in_width-1;
out_height=in_height-1;
output.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, 'Y800', 2, out_width, out_height);
output.publish();
blc_loop_try_add_waiting_semaphore(output.sem_ack_data);
blc_loop_try_add_posting_semaphore(output.sem_new_data);
BLC_COMMAND_LOOP(0){
FOR(j, out_height){
FOR(i, out_width){
output.uchars[i+j*out_width]=(IN(i, j)+IN(i+1, j)+IN(i+2,j)\
+ IN(i, j+1)+IN(i+1, j+1)+IN(i+2,j+1)\
+ IN(i, j+2)+IN(i+1, j+2)+IN(i+2,j+2))/9;
}
}
}
return EXIT_SUCCESS;
}
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(i_d2gaussian)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_d2gaussian i_d2gaussian.cpp)
target_link_libraries(i_d2gaussian ${BL_LIBRARIES})
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":d2gaussian<pid>"
int main(int argc, char **argv){
blc_channel output;
char const *output_name, *size_str, *type_str, *sigma_str, *gain_str;
float sigma, coeff, x, y, gain;
int i, j, id, jd;
uint32_t type;
blc_program_set_description("Create second derivative gaussian");
blc_program_add_option(&gain_str, 'g', "gain", "real", "gain to apply to the filter", "1");
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_option(&size_str, 's', "size", "(integer)[x(integer)]", "size of the output 1 or 2D", "3x3");
blc_program_add_option(&type_str, 't', "type", "FL32", "type of values", "FL32");
blc_program_add_option(&sigma_str, 'S', "sigma", "float", "sigma of the initial gaussian", "1");
blc_program_init(&argc, &argv, blc_quit);
if (strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) SYSTEM_ERROR_CHECK(asprintf((char**)&output_name, ":d2gaussian%d", getpid()),-1, NULL);
type=STRING_TO_UINT32(type_str);
SSCANF(1, gain_str, "%f", &gain);
SYSTEM_SUCCESS_CHECK(sscanf(sigma_str, "%f", &sigma), 1, "Error parsing '%s'", sigma_str);
output.create_or_open(output_name, BLC_CHANNEL_WRITE, type, 'NDEF', size_str);
output.publish();
// 1/(pi*sigma²)(1-1/2(x²+y²)/sigma²)*exp(-1/2*(x²+y²)/sigma²)
FOR(j, output.dims[1].length){
FOR(i, output.dims[0].length){
x=i-(float)output.dims[0].length/2.0+0.5;
y=j-(float)output.dims[1].length/2.0+0.5;
coeff=(x*x+y*y)/(float)(2*sigma*sigma); //(x²+y²)/(2*sigma²)
output.floats[i+j*output.dims[0].length]=gain/(M_PI*sigma*sigma)*(1-coeff)*exp(-coeff);
}
}
if (output.sem_ack_data) sem_wait(output.sem_ack_data);
if (output.sem_new_data) sem_post(output.sem_new_data);
BLC_COMMAND_LOOP(-1){};
return EXIT_SUCCESS;
}
... ...