How can I get the built in Edge function to work in a dll?

1 view (last 30 days)
Hello, I'm having a problem using the edge function when I am trying to create a DLL in Matlab. I have created a function that takes in an array (1360,1024, uint16) and performs the Matlab built-in edge function. When I run the function in Matlab I am able to write out the (1360, 1024, logical) and see that there are 0's and 1's in the file. Along with the Original Array.
But when I create a DLL from the same function it will only write out all 0's. But I am able to write out the original array just fine.
I'm a little confused to why this will not work for me. If someone could please help that would be great. Below is the function.
function edgeThis( a )
%"a" is a 1360x1024 unit16 array (image from camera)
%outImg will be the edge detection
%outImg2 will be the original image from the camera.
outImg = edge(a,'log',1');
outName = 'C:\Users\user\Desktop\edgeMe.bin';
%writes out Edge file in matlab with 0's and 1's but not in DLL
fid = fopen(outName,'w');
fwrite(fid,outImg,'uint16');
fclose(fid);
%write out original array in both Matlab and DLL
outName2 = 'C:\Users\user\Desktop\org.bin';
fid = fopen(outName2,'w');
fwrite(fid,a,'uint16');
fclose(fid);
end
--------------------The C++ code looks like this. ----------------------
#include<iostream>
#include <vector>
#include <conio.h>
#include <ctype.h>
#include <fstream>
#include "edgeThis.h"
using namespace std;
int run_main(int argc, char **argv)
{
if (!mclInitializeApplication(NULL,0))
{
std::cerr << "could not initialize the application properly"
<< std::endl;
return -1;
}
if( !edgeThisInitialize() )
{
std::cerr << "could not initialize the library properly"
<< std::endl;
return -1;
}
try
{
int numCol = 1360;
int numRow = 1024;
//create matlab array of size numRow,numCol uint16
mwArray inData(numCol, numRow, mxUINT16_CLASS, mxREAL);
//declare space for array being read in
std::vector <unsigned short> a;
band1.resize(numCol*numRow);
//file being read in
std::string file ("C:\\Users\\user\\Desktop\\dataFile.data");
ifstream myFile (file, ios::in | ios::binary);
//store data from file in variable a
myFile.read((char*) &a[0],numCol*numRow*sizeof(short));
myFile.close();
//set inData to be data from disk read
inData.SetData(&a[0], (mwSize)(numRow*numCol));
//create edge image and write out using matlab dll
//***Again this is where I am having the issue. It will now write out all 0's for the edge file but the original image will be written out just fine through the DLL*****
edgeThis(indata);
}
catch (const mwException& e)
{
std::cerr << e.what() << std::endl;
return -2;
}
catch (...)
{
std::cerr << "Unexpected error thrown" << std::endl;
return -3;
}
edgeThisTerminate();
mclTerminateApplication();
return 0;
int main()
{
mclmcrInitialize();
int ret= mclRunMain((mclMainFcnType)run_main,0,NULL);
_getch(); //if a characture is hit then window is closed
return ret;
}

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!