필터 지우기
필터 지우기

Integrating C++ code with Matlab Code

조회 수: 2 (최근 30일)
Amarjot
Amarjot 2013년 3월 8일
Hi, I am computing the output of an image using two components of a code. One component is in C++ while the other one is in matlab. I run the c++ component on my image, save it in a folder and then run my matlab code on it. Is it possible to integrate them together. Like my C++ code runs in matlab and then automatically passes the output to my matlab code??
Thanks for your help.
Amarjot

채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 8일
Using mex you can have MATLAB call the C++ part and retrieve the output.
  댓글 수: 2
Amarjot
Amarjot 2013년 3월 8일
Thank you very much.
Amarjot
Amarjot 2013년 3월 9일
편집: Walter Roberson 2013년 3월 9일
Hi i just looked into it. I think, i just need to modify the main file according to matlab. Can you please give me an idea how i can modify it. Here is my main file (Sorry i am very new to it)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "retinex_pde_lib.h"
#include "io_png.h"
#include "norm.h"
#include "mex.h"
/**
* @brief main function call
*/
int main(int argc, char *const *argv)
{
float t; /* retinex threshold */
size_t nx, ny, nc; /* image size */
size_t channel, nc_non_alpha;
float *data, *data_rtnx;
/* "-v" option : version info */
if (2 <= argc && 0 == strcmp("-v", argv[1])) {
fprintf(stdout, "%s version " __DATE__ "\n", argv[0]);
return EXIT_SUCCESS;
}
/* wrong number of parameters : simple help info */
if (4 != argc) {
fprintf(stderr, "usage : %s T in.png rtnx.png\n", argv[0]);
fprintf(stderr, " T retinex threshold [0...255]\n");
return EXIT_FAILURE;
}
/* retinex threshold */
t = atof(argv[1]);
if (0. > t || 255. < t) {
fprintf(stderr, "the retinex threshold must be in [0..255]\n");
return EXIT_FAILURE;
}
/* read the PNG image into data */
if (NULL == (data = read_png_f32(argv[2], &nx, &ny, &nc))) {
fprintf(stderr, "the image could not be properly read\n");
return EXIT_FAILURE;
}
/* allocate data_rtnx and fill it with a copy of data */
if (NULL == (data_rtnx = (float *) malloc(nc * nx * ny * sizeof(float)))) {
fprintf(stderr, "allocation error\n");
free(data);
return EXIT_FAILURE;
}
memcpy(data_rtnx, data, nc * nx * ny * sizeof(float));
/* the image has either 1 or 3 non-alpha channels */
if (3 <= nc)
nc_non_alpha = 3;
else
nc_non_alpha = 1;
/*
* run retinex on each non-alpha channel data_rtnx,
* normalize mean and standard deviation and save
*/
for (channel = 0; channel < nc_non_alpha; channel++) {
if (NULL == retinex_pde(data_rtnx + channel * nx * ny, nx, ny, t)) {
fprintf(stderr, "the retinex PDE failed\n");
free(data_rtnx);
free(data);
return EXIT_FAILURE;
}
normalize_mean_dt(data_rtnx + channel * nx * ny,
data + channel * nx * ny, nx * ny);
}
write_png_f32(argv[3], data_rtnx, nx, ny, nc);
free(data_rtnx);
free(data);
return EXIT_SUCCESS;
}

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by