Skip to content

Commit

Permalink
for droplet analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ting Xu committed Nov 9, 2014
1 parent 07e49c2 commit 5678f66
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 90 deletions.
22 changes: 9 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ set(gui_srcs

set(common_srcs
global.h
# multisnake.h
# multisnake.cc
snake.h
snake.cc
solver_bank.h
Expand All @@ -68,17 +66,15 @@ set(moc_gui_srcs

set(rcc_srcs icons.qrc)

# add_definitions(-Wall)

qt4_wrap_cpp(multisnake_moc multisnake.h)
qt4_wrap_cpp(mocs ${moc_gui_srcs})
qt4_add_resources(rccs ${rcc_srcs})

add_executable(soax soax.cc ${common_srcs} ${gui_srcs} ${mocs}
${rccs} ${multisnake_moc} multisnake.cc multisnake.h)

# add_executable(batch_soax batch_soax.cc ${common_srcs}
# ${multisnake_moc} multisnake.cc multisnake.h)
add_executable(batch_soax batch_soax.cc ${common_srcs}
${multisnake_moc} multisnake.cc multisnake.h)
# # add_executable(eval_gt evaluate_gt.cc ${common_srcs})
# # add_executable(eval_f evaluate_f.cc ${common_srcs})
# add_executable(best_snake best_snake.cc ${common_srcs}
Expand All @@ -97,13 +93,13 @@ target_link_libraries(soax
${Boost_PROGRAM_OPTIONS_LIBRARY}
)

# target_link_libraries(batch_soax
# ${QT_LIBRARIES}
# ${ITK_LIBRARIES}
# ${Boost_PROGRAM_OPTIONS_LIBRARY}
# ${Boost_FILESYSTEM_LIBRARY}
# ${Boost_SYSTEM_LIBRARY}
# )
target_link_libraries(batch_soax
${QT_LIBRARIES}
${ITK_LIBRARIES}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
)

# target_link_libraries(eval_gt
# ${ITK_LIBRARIES}
Expand Down
87 changes: 66 additions & 21 deletions main_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ void MainWindow::CreateProcessMenuActions() {
group_snakes_ = new QAction(tr("Group Snakes"), this);
group_snakes_->setIcon(QIcon(":/icon/Favorites.png"));
connect(group_snakes_, SIGNAL(triggered()), this, SLOT(GroupSnakes()));

find_correspondence_ = new QAction(tr("Find Correspondence for Sequence"), this);
connect(find_correspondence_, SIGNAL(triggered()), this, SLOT(FindCorrespondence()));
}

void MainWindow::CreateAnalysisMenuActions() {
Expand Down Expand Up @@ -397,16 +400,9 @@ void MainWindow::CreateMenus() {
process_->addAction(deform_snakes_for_sequence_);
process_->addAction(cut_snakes_);
process_->addAction(group_snakes_);
process_->addAction(find_correspondence_);

analysis_ = menuBar()->addMenu(tr("&Analysis"));
// actin_cable_submenu_ = analysis_->addMenu(tr("Actin Cable"));
// contractile_ring_submenu_ = analysis_->addMenu(tr("Contractile Ring"));
// fibrin_submenu_ = analysis_->addMenu(tr("Fibrin Network"));
// fibrin_submenu_->addAction(compute_spherical_orientation_);
// droplet_submenu_ = analysis_->addMenu(tr("Actin Droplet"));
// droplet_submenu_->addAction(compute_radial_orientation_);
// droplet_submenu_->addAction(compute_point_density_);
// droplet_submenu_->addAction(compute_curvature_);
analysis_->addAction(compute_spherical_orientation_);
analysis_->addAction(compute_radial_orientation_);
analysis_->addAction(compute_point_density_);
Expand Down Expand Up @@ -507,6 +503,7 @@ void MainWindow::ResetActions() {
deform_snakes_for_sequence_->setEnabled(false);
cut_snakes_->setEnabled(false);
group_snakes_->setEnabled(false);
find_correspondence_->setEnabled(false);

compute_spherical_orientation_->setEnabled(false);
compute_radial_orientation_->setEnabled(false);
Expand Down Expand Up @@ -780,6 +777,7 @@ void MainWindow::LoadSnakesSequence() {
viewer_->set_snake_filename(snake_filename_);
viewer_->SetupUpperRightCornerText();
toggle_corner_text_->setChecked(true);
find_correspondence_->setEnabled(true);
// save_jfilament_snakes_->setEnabled(true);
// compare_snakes_->setEnabled(true);
// toggle_delete_snake_->setEnabled(true);
Expand Down Expand Up @@ -962,12 +960,19 @@ void MainWindow::CloseSession() {
viewer_->Reset();
viewer_->Render();
multisnake_->Reset();
disconnect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(UpdateSnakesJunctions(int)));
disconnect(multisnake_, SIGNAL(ExtractionCompleteForFrame(int)),
progress_bar_, SLOT(setValue(int)));
disconnect(multisnake_, SIGNAL(ExtractionCompleteForFrame(int)),
progress_bar_, SLOT(setValue(int)));

disconnect(scroll_bar_, SIGNAL(valueChanged(int)), viewer_, SLOT(UpdateFrame(int)));
disconnect(scroll_bar_, SIGNAL(valueChanged(int)), this, SLOT(ShowFrameNumber(int)));
disconnect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(UpdateLeftCornerText(int)));
disconnect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(UpdateSnakesJunctions(int)));
disconnect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(HighlightCorrespondingSnake(int)));

this->ResetActions();
open_image_->setEnabled(true);
Expand Down Expand Up @@ -1204,6 +1209,7 @@ void MainWindow::DeformSnakesForSequence() {
this->ViewSnakesSequence();
initialize_snakes_for_sequence_->setEnabled(false);
save_snakes_sequence_->setEnabled(true);
find_correspondence_->setEnabled(true);
// deform_snakes_->setEnabled(false);
// save_snakes_->setEnabled(true);
// save_jfilament_snakes_->setEnabled(true);
Expand All @@ -1227,6 +1233,12 @@ void MainWindow::DeformSnakesForSequence() {
// show_analysis_options_->setEnabled(true);
}

void MainWindow::FindCorrespondence() {
viewer_->SolveCorrespondence();
connect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(HighlightCorrespondingSnake(int)));
}

void MainWindow::ViewSnakesSequence() {
connect(scroll_bar_, SIGNAL(valueChanged(int)),
viewer_, SLOT(UpdateSnakesJunctions(int)));
Expand Down Expand Up @@ -1289,33 +1301,57 @@ void MainWindow::ComputeSphericalOrientation() {
this, tr("Save spherical orientation"), "..",
tr("Text files(*.txt)"));
if (filename.isEmpty()) return;
multisnake_->ComputeSphericalOrientation(filename.toStdString());

std::ofstream outfile;
outfile.open(filename.toStdString().c_str());
if (!outfile.is_open()) {
QMessageBox msg_box;
msg_box.setText("Opening file failed.");
msg_box.setIcon(QMessageBox::Critical);
msg_box.exec();
return;
}

multisnake_->ComputeSphericalOrientation(outfile);
statusBar()->showMessage(tr("Spherical orientation file saved."));
outfile.close();
}

void MainWindow::ComputeRadialOrientation() {
QString filename = QFileDialog::getSaveFileName(
this, tr("Save radial orientation file"), "..",
this, tr("Save radial orientation"), "..",
tr("Text files(*.txt)"));
if (filename.isEmpty()) return;

PointType center;
analysis_options_dialog_->GetImageCenter(center);
std::cout << "Image center: " << center << std::endl;
multisnake_->ComputeRadialOrientation(center, filename.toStdString());
double pixel_size = analysis_options_dialog_->GetPixelSize();

std::ofstream outfile;
outfile.open(filename.toStdString().c_str());
if (!outfile.is_open()) {
QMessageBox msg_box;
msg_box.setText("Opening file failed.");
msg_box.setIcon(QMessageBox::Critical);
msg_box.exec();
return;
}

multisnake_->ComputeRadialOrientation(center, pixel_size, outfile);
statusBar()->showMessage(tr("Radial orientation file saved."));
outfile.close();
}

void MainWindow::ComputePointDensity() {
QString filename = QFileDialog::getSaveFileName(
this, tr("Save SOAC point density/intensity file"), "..",
this, tr("Save SOAC point density/intensity"), "..",
tr("Text files(*.txt)"));
if (filename.isEmpty()) return;

PointType center;
analysis_options_dialog_->GetImageCenter(center);
unsigned max_radius = analysis_options_dialog_->GetRadius();
double pixel_size = analysis_options_dialog_->GetPixelSize();
std::cout << "pixel size: " << pixel_size << std::endl;

std::ofstream outfile;
outfile.open(filename.toStdString().c_str());
Expand All @@ -1329,19 +1365,28 @@ void MainWindow::ComputePointDensity() {

multisnake_->ComputePointDensityAndIntensity(center, max_radius,
pixel_size, outfile);
statusBar()->showMessage(tr("SOAC point density/intensity file saved."));
outfile.close();
statusBar()->showMessage(
tr("SOAC point density/intensity written successfully."));
}

void MainWindow::ComputeCurvature() {
QString filename = QFileDialog::getSaveFileName(
this, tr("Save curvature file"), "..", tr("Text files(*.txt)"));
this, tr("Save curvature"), "..", tr("Text files(*.txt)"));
if (filename.isEmpty()) return;
int coarse_graining = analysis_options_dialog_->GetCoarseGraining();
std::cout << coarse_graining << std::endl;
multisnake_->ComputeCurvature(coarse_graining, filename.toStdString());

std::ofstream outfile;
outfile.open(filename.toStdString().c_str());
if (!outfile.is_open()) {
QMessageBox msg_box;
msg_box.setText("Opening file failed.");
msg_box.setIcon(QMessageBox::Critical);
msg_box.exec();
return;
}
multisnake_->ComputeCurvature(coarse_graining, outfile);
statusBar()->showMessage(tr("Curvature file saved."));
outfile.close();
}

void MainWindow::ShowAnalysisOptions() {
Expand Down
2 changes: 2 additions & 0 deletions main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MainWindow : public QMainWindow {
void DeformSnakesForSequence();
void CutSnakes();
void GroupSnakes();
void FindCorrespondence();

void ComputeSphericalOrientation();
void ComputeRadialOrientation();
Expand Down Expand Up @@ -152,6 +153,7 @@ class MainWindow : public QMainWindow {
QAction *deform_snakes_for_sequence_;
QAction *cut_snakes_;
QAction *group_snakes_;
QAction *find_correspondence_;

// Actions in Analysis menu
QAction *compute_spherical_orientation_;
Expand Down
57 changes: 13 additions & 44 deletions multisnake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1457,37 +1457,26 @@ void Multisnake::PrintGroundTruthLocalSNRValues(int radial_near,


void Multisnake::ComputeRadialOrientation(const PointType &center,
const std::string &filename) const {
double pixel_size,
std::ostream & os) const {
if (converged_snakes_.empty()) return;

std::ofstream outfile;
outfile.open(filename.c_str());
if (!outfile.is_open()) {
std::cerr << "Cannot open file for radial orientation results."
<< std::endl;
return;
}

const unsigned width = 15;
outfile << "Image file\t" << image_filename_ << "\n"
const unsigned width = 16;
os << "Image file\t" << image_filename_ << "\n"
<< "Image center\t" << center << "\n"
<< std::setw(width) << "radius (um)"
<< std::setw(width) << "theta" << std::endl;

const double spacing = 0.166; // droplet image

for (SnakeConstIterator it = converged_snakes_.begin();
it != converged_snakes_.end(); ++it) {
for (unsigned i = 0; i < (*it)->GetSize() - 1; ++i) {
double r, theta;
this->ComputeRTheta((*it)->GetPoint(i), (*it)->GetPoint(i+1),
center, r, theta);
outfile << std::setw(width) << r * spacing
os << std::setw(width) << r * pixel_size
<< std::setw(width) << theta << std::endl;
}
}

outfile.close();
}

void Multisnake::ComputeRTheta(const PointType &point1,
Expand Down Expand Up @@ -1572,17 +1561,8 @@ void Multisnake::ComputePointDensityAndIntensity(const PointType &center,
}
}

void Multisnake::ComputeCurvature(int coarse_graining,
const std::string &filename) const {
std::ofstream outfile;
outfile.open(filename.c_str());
if (!outfile.is_open()) {
std::cerr << "Cannot open file for snake point density results."
<< std::endl;
return;
}

outfile << "Image file\t" << image_filename_ << "\n"
void Multisnake::ComputeCurvature(int coarse_graining, std::ostream &os) const {
os << "Image file\t" << image_filename_ << "\n"
<< "Coarse graining\t" << coarse_graining << std::endl;

for (SnakeConstIterator it = converged_snakes_.begin();
Expand All @@ -1598,24 +1578,14 @@ void Multisnake::ComputeCurvature(int coarse_graining,
vec2.Normalize();
double length = coarse_graining * (*it)->spacing();
double curvature = (vec1 - vec2).GetNorm() / length;
outfile << curvature << std::endl;
os << curvature << std::endl;
}
}
outfile.close();
}

void Multisnake::ComputeSphericalOrientation(
const std::string &filename) const {
std::ofstream outfile;
outfile.open(filename.c_str());
if (!outfile.is_open()) {
std::cerr << "Cannot open file for snake point density results."
<< std::endl;
return;
}

const unsigned width = 15;
outfile << "Image file\t" << image_filename_ << "\n"
void Multisnake::ComputeSphericalOrientation(std::ostream &os) const {
const unsigned width = 16;
os << "Image file\t" << image_filename_ << "\n"
<< std::setw(width) << "theta"
<< std::setw(width) << "phi" << std::endl;
for (SnakeConstIterator it = converged_snakes_.begin();
Expand All @@ -1624,11 +1594,10 @@ void Multisnake::ComputeSphericalOrientation(
VectorType vector = (*it)->GetPoint(i) - (*it)->GetPoint(i+1);
double theta, phi;
this->ComputeThetaPhi(vector, theta, phi);
outfile << std::setw(width) << theta
<< std::setw(width) << phi << std::endl;
os << std::setw(width) << theta
<< std::setw(width) << phi << std::endl;
}
}
outfile.close();
}

void Multisnake::ComputeThetaPhi(VectorType vector,
Expand Down
8 changes: 4 additions & 4 deletions multisnake.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ class Multisnake : public QObject {
void PrintGroundTruthLocalSNRValues(int radial_near, int radial_far) const;

void ComputeRadialOrientation(const PointType &center,
const std::string &filename) const;
double pixel_size,
std::ostream & os) const;

void ComputePointDensityAndIntensity(const PointType &center,
unsigned max_r, double pixel_size,
std::ostream & os) const;

void ComputeCurvature(int coarse_graining,
const std::string &filename) const;
void ComputeSphericalOrientation(const std::string &filename) const;
void ComputeCurvature(int coarse_graining, std::ostream &os) const;
void ComputeSphericalOrientation(std::ostream &os) const;

void DeleteSnakes(const SnakeSet &snakes);

Expand Down
12 changes: 7 additions & 5 deletions snake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,17 @@ double Snake::ComputeBackgroundMeanIntensity(bool is_head) const {
this->ComputeSamplePoint(sample_point, vertex, radial, normal, d, s);
if (this->IsInsideImage(sample_point)) {
double intensity = interpolator_->Evaluate(sample_point);
bgs.push_back(intensity);
if (intensity > background_)
bgs.push_back(intensity);
}
}
}

int number_of_samples = number_of_sectors_ * (radial_far_ - radial_near_);
unsigned threshold = static_cast<unsigned>(number_of_samples * 0.5);
// std::cout << threshold << std::endl;
if (bgs.size() < threshold) {
// int number_of_samples = number_of_sectors_ * (radial_far_ - radial_near_);
// unsigned threshold = static_cast<unsigned>(number_of_samples * 0.5);

// if (bgs.size() < threshold) {
if (bgs.empty()) {
return -1.0; // return a negative value intentionally
} else {
return Mean(bgs);
Expand Down
Loading

0 comments on commit 5678f66

Please sign in to comment.