我一直在学习一些OpenCV,它是免费的,可用于 OSX、Linux 和 Windows。我认为它可能会为您的问题增加一些交互性,所以我实现了与 ImageMagick 中完全相同的算法,但在我的初学者OpenCV 中。如果任何更有经验的人对我的代码有任何建设性的指导方针,我会全力以赴。
不管怎样,运行时它看起来像这样,你滑动阈值滑块:
代码如下:
////////////////////////////////////////////////////////////////////////////////
// NerveView.cpp
// Mark Setchell
//
// OpenCV program that takes two images as parameters, the first the red
// fluorescent nerve image and the second which is the green image.
//
// The two images are resized, normalised and then displayed merged into a
// single RGB image where the thresholds on red and green are controlled by
// sliders. Common areas therefore appear in yellow. Move either slider left
// to lower the threshold and therefore include more of that colour in the
// combined output image, or move slider right to decrease amount of that
// colour.
//
// Run with:
//
// ./NerveView red.jpg green.jpg
//
// Compile with:
//
// g++ `pkg-config --cflags --libs opencv` NerveView.cpp -o NerveView
//
////////////////////////////////////////////////////////////////////////////////
#include <sstream>
#include <string>
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
// Temp workspace
Mat tmp1,tmp2;
// Image size
Size size(640,480);
// Create a window for controls
namedWindow("Controls", CV_WINDOW_NORMAL);
resizeWindow("Controls",640,100);
// Create slider to change Red threshold
int RedThreshold = 50;
createTrackbar("Red Threshold Percentage", "Controls", &RedThreshold, 100);
// Create slider to change Green threshold
int GreenThreshold = 50;
createTrackbar("Green Threshold Percentage", "Controls", &GreenThreshold, 100);
// Create variables to store input images and load them
Mat Red,Green;
Mat planes[3];
// Load red image, split, discard G & B, resize, normalize
tmp1 = imread(argv[1], CV_LOAD_IMAGE_COLOR);
split(tmp1,planes);
resize(planes[2],tmp1,size);
normalize(tmp1,Red,0,255,NORM_MINMAX,CV_8UC1);
// Load green image, split, discard R & B, resize, normalize
tmp1 = imread(argv[2], CV_LOAD_IMAGE_COLOR);
split(tmp1,planes);
resize(planes[1],tmp1,size);
normalize(tmp1,Green,0,255,NORM_MINMAX,CV_8UC1);
// Make empty Blue channel, same size
Mat Blue=Mat::zeros(size,CV_8UC1);
//Create window to display images
cv::namedWindow("Image", CV_WINDOW_AUTOSIZE);
// Create variable to store the processed image
Mat img=Mat::zeros(640,480,CV_8UC3);
while (true){
// Get thresholds, apply to their channels and combine to form result
threshold(Red,tmp1,(RedThreshold*255)/100,255,THRESH_BINARY);
threshold(Green,tmp2,(GreenThreshold*255)/100,255,THRESH_BINARY);
// Combine B, G and R channels into "img"
vector<Mat> channels;
channels.push_back(Blue);
channels.push_back(tmp2);
channels.push_back(tmp1);
merge(channels,img);
// Display result
imshow("Image",img);
// See if user pressed a key
int key=cvWaitKey(50);
if(key>=0)break;
}
return 0;
}
关键词:神经、神经、荧光