在输入图像上应用SLIC superpixel
之后,我需要从红色,蓝色和绿色通道中获取标签的最大值。
我编写了这段代码,首先我应用了SLIC Superpixel
,然后使用split命令获得了3个通道。然后,我使用了Core.minMaxLoc
命令。
我的问题是,Core.minMaxLoc
返回的最大值是像素或标签的最大值?因为我需要从标签而不是像素中提取最大值。
这是我的代码:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "3:qinQctivity";
Button button;
ImageView imageView,imageView_red,imageView_blue,imageView_green;
TextView textView,mean_text;
Double Max_Red,Max_Green,Max_Blue;
Mat newImage,newMat,mask,labels,BGR_RGB,Blue,Green,Red;
ArrayList<Mat> RGB = new ArrayList<Mat>(3);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
imageView = findViewById(R.id.image);
imageView_red = findViewById(R.id.image_red);
imageView_blue = findViewById(R.id.image_blue);
imageView_green = findViewById(R.id.image_green);
textView = findViewById(R.id.textView);
mean_text = findViewById(R.id.textView2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!OpenCVLoader.initDebug()) {
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_4_0, getApplicationContext(), baseLoaderCallback);
} else {
baseLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
});
}
BaseLoaderCallback baseLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
super.onManagerConnected(status);
if (status == LoaderCallbackInterface.SUCCESS) {
try {
newImage = new Mat();
newMat = new Mat();
labels = new Mat();
BGR_RGB = new Mat();
BGR_RGB = Utils.loadResource(getApplicationContext(), R.drawable.retinalimage, CvType.CV_32FC3);
Imgproc.cvtColor(BGR_RGB,newImage,Imgproc.COLOR_BGR2RGB);
SuperpixelSLIC x = Ximgproc.createSuperpixelSLIC(newImage, Ximgproc.SLIC, 50, (float) 0.001);
x.iterate(5);
if (true){
x.enforceLabelConnectivity(20);
}
mask = new Mat();
x.getLabelContourMask(mask, true);
newImage.setTo(new Scalar(0, 0, 255), mask);
showImage(newImage);
labels = new Mat();
x.getLabels(labels);
//count the number of the superpixel segmented regions
int a = x.getNumberOfSuperpixels();
// working on the Red, Blue and green channel
Core.split(newImage,RGB);
Red = RGB.get(0);
Green = RGB.get(1);
Blue = RGB.get(2);
Max_Red = Core.minMaxLoc(Red).maxVal;
Max_Green = Core.minMaxLoc(Green).maxVal;
Max_Blue = Core.minMaxLoc(Blue).maxVal;
Scalar P = Core.mean(newImage);
textView.setText(String.valueOf(P));
mean_text.setText(String.valueOf(P));
showImage(newImage);
} catch (IOException e) {
e.printStackTrace();
}
}
}
} ;