Reputation: 45
After applying SLIC superpixel
on an input image, I need to get the max value of the labels from the Red, Blue and Green channel.
I wrote this code, First I applied the SLIC Superpixel
and then I used the split command to get the 3 channels. Then i used the Core.minMaxLoc
command.
My question is, the Max returned from Core.minMaxLoc
is the Max of pixels or the labels? Because I need to extract the maximum value from the labels not the pixel.
This is my code:
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();
}
}
}
} ;
Upvotes: 0
Views: 640