Commit ec06a61a authored by Tony Cheung's avatar Tony Cheung

Upload New File

parent 4de9685e
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
double** CreateArray(string ImageFile, int &Width, int &Height)
{
Mat image;
Scalar intensity;
double pixel_intensity = 0.;
image = imread(ImageFile, 0); // Read the file
//cout << image.cols << endl;
//cout << image.rows << endl;
Height = image.rows;
Width = image.cols;
double** ary = new double*[Width];
for (int i = 0; i < Width; i++)
ary[i] = new double[Height];
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
intensity = image.at<uchar>(j, i);
pixel_intensity = intensity.val[0];
ary[j][i] = pixel_intensity;
}
}
//cout << ary[330][104] << endl;
return ary;
}
void CreateSegmentedImage(double** ImageArray, double** MaskArray, int &Width, int &Height)
{
cv::Mat Segment(Width, Height, CV_8UC1);
for (int i = 0; i < Width; ++i)
{
for (int j = 0; j < Height; ++j)
{
Segment.at<uchar>(i, j) = (ImageArray[i][j]) * (MaskArray[i][j] / 255.0);
}
}
//cout << ImageSegment[271][264] << endl;
imwrite("SegmentedAirway.png", Segment);
return;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
cout << " Usage: " << argv[0] << " InputImage.png InputMask.png" << endl;
return -1;
}
double** imagearray = nullptr;
double** maskarray = nullptr;
int width = 0;
int height = 0;
imagearray = CreateArray(argv[1], width, height);
maskarray = CreateArray(argv[2], width, height);
CreateSegmentedImage(imagearray, maskarray, width, height);
//cout << imagearray[271][264] << endl;
//cout << maskarray[271][264] << endl;
for (int i = (width - 1); i >= 0; i--)
{
delete[] imagearray[i];
delete[] maskarray[i];
}
delete[] imagearray;
delete[] maskarray;
imagearray = nullptr;
maskarray = nullptr;
return 0;
}
//output
//see the SegmentedAirway.png
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment