main.cpp 3.81 KB
#include <stim/image/image.h>
#include <cmath>
#include <stim/visualization/colormap.h>
#include <stim/image/image_contour_detection.h>
#include <iostream>
#include <stim/visualization/colormap.h>

/// calculate the cPb, tPb and mPb given a multi-channel image

void array_multiply(float* lhs, float rhs, unsigned int N);
void array_add(float* ptr1, float* ptr2, float* sum, unsigned int N);

int main()
{
	stim::image<float> image;                           // generate an image object

	image.load("101085.bmp");					// load the input image
	//image.load("slice00_500_500.bmp");					// load the input image
	image = image.channel(0);                           // get the first channel of black-and-white image


	unsigned int w = image.width();		  // get the width of picture
	unsigned int h = image.height();      // get the height of picture
	unsigned int N = w * h;				  // get the number of pixels
	int c = image.channels();             // get the number if channels of picture
	int s = 3;						      // set the number of scales
	int r1[3] = {3,5,10};                 // set an array of radii for different scaled discs(filters) for cPb, the length of r is c*s
	int r2[3] = {5,10,20};                // set an array of radii for different scaled discs(filters) for tPb, the length of r is c*s
	float alpha[3] = {1,1,1};             // set an array of weights for different scaled discs(filters)
	unsigned int theta_n = 8;             // set the number of angles used in filter orientation
	unsigned int bin_n = 16;              // set the number of bins used in chi-distance
	unsigned int K = 16;				  // set the number of cludters, K should be multiple of bin_n
	
	stim::image<float> img_cPb(w, h);				// allocate the space for cPb
	stim::image<float> img_tPb(w, h);				// allocate the space for tPb
	stim::image<float> img_mPb(w, h);				// allocate the space for tPb

	std::cout<<"imagesize: "<< w <<"*"<< h <<'\n';

	//*******************cPb********************
	std::cout<<"begin cPb"<<'\n';     


	std::clock_t start1;      // (optional) set the timer to calculate the total time 
	start1 = std::clock();    // (optional) set timer start point

	img_cPb = cPb(image, r1, alpha, s);      
	
	// show the cPb (optional)	
    stim::cpu2image(img_cPb.data(), "data_output/img_cPb_0925.bmp", w, h, stim::cmBrewer); 

	double duration1 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time 
	std::cout<<"cPb time: "<< duration1 <<"s"<<'\n';                      // (optional) show the total time 
	

	//*******************tPb********************
	std::cout<<"begin tPb"<<'\n';     
	

	std::clock_t start2;      // (optional) set the timer to calculate the total time 
	start2 = std::clock();    // (optional) set timer start point

	img_tPb = tPb(image, r2, alpha, theta_n, bin_n, s, K);
	
	// show the tPb (optional)
	stim::cpu2image(img_tPb.data(), "data_output/img_tPb_0925.bmp", w, h, stim::cmBrewer); 

	double duration2 = ( std::clock() - start2 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time 
	std::cout<<"tPb time: "<< duration2 <<"s"<<'\n';                      // (optional) show the total time 

	
	//*******************************************

	double duration3 = ( std::clock() - start1 ) / (double) CLOCKS_PER_SEC; // (optional) calculate the total time 
	std::cout<<"total running time: "<< duration3 <<"s"<<'\n';                      // (optional) show the total time 
	
	//******************mPb**********************
	// set parameters for linear combination
	float a = 1;
	float b = 0.5;

	// create mPb by linearly combined cPb and tPb
	array_multiply(img_cPb.data(), a, N);
	array_multiply(img_tPb.data(), b, N);
	array_add(img_cPb.data(), img_tPb.data(), img_mPb.data(), N);

	// show the mPb (optional)
	stim::cpu2image(img_mPb.data(), "data_output/img_mPb_0925.bmp", w, h, stim::cmBrewer); 

	return 0;

}