Commit acdf0a2a authored by Yipeng Hu's avatar Yipeng Hu

Merge branch 'patch-5' into 'master'

Add new directory

See merge request !3
parents ac4e7879 3584d7b6
#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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int GetTotalchar(string filename)
{
ifstream inFile(filename);
int size = 0;
char c;
while (inFile.get(c))
{
size++;
}
inFile.close();
return size;
}
char* GetSequence(string filename, int total)
{
ifstream inFile(filename);
// allocate memory for storing sequence
char* sequence = new char[total];
char c;
int i = 0;
while (inFile.get(c))
{
sequence[i] = c;
i++;
}
inFile.close();
return sequence;
}
void CountSequence(char *sequence, int totalchar)
{
int count_A = 0;
int count_T = 0;
int count_C = 0;
int count_G = 0;
char c;
for (int i = 0; i < totalchar; i++)
{
c = sequence[i];
if (c == 'A')
count_A++;
if (c == 'T')
count_T++;
if (c == 'C')
count_C++;
if (c == 'G')
count_G++;
}
cout << "Total number of A is: " << count_A << endl;
cout << "Total number of T is: " << count_T << endl;
cout << "Total number of C is: " << count_C << endl;
cout << "Total number of G is: " << count_G << endl;
cout << "The length of the sequence is: " << totalchar << endl;
cout << endl;
}
void AnalyseSequence(char *sequence1, char *sequence2, int totalchar1, int totalchar2)
{
char c1, c2;
int CountIdenticalChar = 0;
double similarity = 0.;
for (int i = 0; i < totalchar1; i++)
{
c1 = sequence1[i];
c2 = sequence2[i];
if (c1 == c2)
CountIdenticalChar++;
}
similarity = ((double) CountIdenticalChar / (double) totalchar1) * 100;
cout << "The similarity of two sequences is: " << similarity << "%" << endl;
}
int main()
{
int totalchar1 = 0;
int totalchar2 = 0;
char* sequence1 = nullptr;
char* sequence2 = nullptr;
string filename1 = "Sequence1.txt";
string filename2 = "Sequence2.txt";
totalchar1 = GetTotalchar(filename1);
sequence1 = GetSequence(filename1, totalchar1);
totalchar2 = GetTotalchar(filename2);
sequence2 = GetSequence(filename2, totalchar2);
cout << "Counting for Sequence 1" << endl;
CountSequence(sequence1, totalchar1);
cout << "Counting for Sequence 2" << endl;
CountSequence(sequence2, totalchar2);
AnalyseSequence(sequence1, sequence2, totalchar1, totalchar2);
// release the memory
delete[] sequence1;
delete[] sequence2;
sequence1 = nullptr;
sequence2 = nullptr;
return 0;
}
//output
/*
Counting for Sequence 1
Total number of A is: 256
Total number of T is: 244
Total number of C is: 240
Total number of G is: 260
The length of the sequence is: 1000
Counting for Sequence 2
Total number of A is: 239
Total number of T is: 267
Total number of C is: 257
Total number of G is: 237
The length of the sequence is: 1000
The similarity of two sequences is: 25.4%
*/
AACGCGTGGCGCCGTCCTTCAAGGAAAGCGGCTGAGTATGCGGTGGTTCAGGTGACGTATCGTGGGCCCCGCTTCTCCAATTCAGATTATTACGATTGTGCGTGAGACAGACGTGACCCGGTTTACCCGTGCGGACGTCATTTAACTGGTTCTTTTTACTGCTGGTCCCTTTCGCGAGACGACACGTGCTGTAGCAGCGGTGAGATATCCCTACAGTTTGGGCCGGAAAACCGGGCCCTAGATCGATTCGGGTGACGCGCTGTGTCTGCTGTTCACCGCTAGAATTTTGATATCAGCCGAGCGGACAAGCCGGGGGTTTGCATATTGCGTCCCACAGCCTATCCACGAGCCACCTTATATAAAGAGGATGTACTCGACGCTGAAGGTACCCTAATTCACAGCATTCGCGAAACAGAAGAGGTACGCCAGTGCCATAAGTACATAGTATCAATTACAGCTAGAGAGGTACATGTTACAACTCATACACCTACACATTCGAATGAGGAAATTATCAGTGATTTAATGGTCTTATGTCTCGTGGTCGGGCGAGGCCATAAAAACCCCATTTATTCAATGCAACTGTCGAATCTCAGGAATATTTTTCACTCTGACGGCTGAAAACCAATGCCCATCGGTGCGTACACCCCGGCTAGCACCTCGGAATTCAAGGGATTGCGGCGTGGAGGGCGCGCAAGTGGCATAGGATGCCCCGACGCGCCCTCGCGTCGCTACCGATGGTGAGCGCGAAGGTCCTAATTAAACTGACATAGATAGCGAAGTGTGTGCAACAATCGAGGGCGACGATTAGGATCAAATTTTAGCTACAGTACAAATACTTAGACTGTATCGAAGGATCCGGACACCGTCTTCTTCATAAGTTGTGCGATTGGCTCAAAGCCTCATCGCCTTCTGAGACTCGCTTTAAGCATAAAACAGAGTCGTACTTTTGTTAAAGGGAATCTTGAGACATGGCGTGACCGTACGATGAGATTTGCGAGAA
\ No newline at end of file
GTTCGCGTGGATTTATATGTAGAGCGGGCTTGTGGCTCTCCAGAGGCCATGGCCGGACAACGCCAGCACGGAAGCGGCTTGTTGCCGCAAGGTTCGAGGGCCCGGAATATTAGTCGACAAGCTACGCATAAAATAGAGGCAAGCGGACGAAGGACTTCCCTCGCTACGGCCGTCTCTAGGCCCTCCAAGCGAGTGGTCTGCCCTCCTCTGTGATCTGCTGGCGCTTACGTTGGCGCGCAAATTGAAGACCAGCCGGCTAACTATAATTAACCTTTTGCAAATCGTAATTAGATACACTTGCCCCTATCCTCGCACATAAAAGTAAAGCTCCAGACTGAGCTTACGTTCCAAGCCACTATCGCGGGTAGCTAGTTGTCTTGCGTAATATTAATATCGGCGACTATAAAGTGCGTATGCCATGTGTTTGACTCAACTGATACCCTTCCAGCATGTACCTTACATGCCGGCATTGTAGCAGACGCTTAGATTTTACTTTAGAGTACTGGCCCGCCCGTTGGAGGCTACTGCATACGCCCCCTATCTCCAGACGCTGGTTTTTTTACATAATACTAGATGGTCATAAATGAGCAAAGCGAGTTAAGCCTACCCCCACGCCTCGTGATTGCAACGGTTATTGCGCGTATTACTACTGGGTTGAAAACTATGTCTTAGCTTTTACGTTACCATGATACTAGCAGTACCACGTGCGTTATTTAGGCTATCGGGCAGCACACCTTCATCTTCGCGCCGTCGCCGTCGCTGAATAAGCTACTCGAACCCGGTCGTTGTAATTGAGATTTTGGAAGTTAAAATCAGCATGCCCAAACGCCTGTACGGAGTGAAGTACCTTCTCTCGGTCTAGAAATACTAGATATAGTCTTTCACGTTCGATGACGGTTAGCCAGTTCGAAATAAGTGTGGACGGAACTGGCCTCCATGTAAGTATCGCTTCTTTCCACTCAAGGACAGGCGGTCCAGCCTGATGTCTTCCTGTATCGTC
\ 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