How to get the values of the local maxima in an image [closed]

asked 2015-05-21 04:08:36 -0600

RB gravatar image

updated 2015-05-21 04:13:37 -0600

I wrote the below code to know how can i get the local and global maximum and minimum, but i do not know how to get the local maxima?

also as you see in the code below, I am using mask, but at run time i receieve the below mentioned error message. so please let me know why do we need mask and how to use it properly.

update:

Line 32 is: MinMaxLocResult s = Core.minMaxLoc(gsMat, mask);

code:

public static void main(String[] args) {
    MatFactory matFactory = new MatFactory();
    FilePathUtils.addInputPath(path_Obj);
    Mat bgrMat = matFactory.newMat(FilePathUtils.getInputFileFullPathList().get(0));

    Mat gsMat = SysUtils.rgbToGrayScaleMat(bgrMat);
    Log.D(TAG, "main", "gsMat.dump(): \n" + gsMat.dump());

    Mat mask = new Mat(new Size(3,3), CvType.CV_8U);//which type i should set for the mask

    MinMaxLocResult s = Core.minMaxLoc(gsMat, mask);
    Log.D(TAG, "main", "s.maxVal: " + s.maxVal);//to get the global maximum
    Log.D(TAG, "main", "s.minVal: " + s.minVal);//to get the global minimum
    Log.D(TAG, "main", "s.maxLoc: " + s.maxLoc);//to get the coordinates of the global maximum
    Log.D(TAG, "main", "s.minLoc: " + s.minLoc);//to get the coordinates of the global minimum
}

error message:

OpenCV Error: Assertion failed (A.size == arrays[i0]->size) in cv::NAryMatIterator::init, file ..\..\..\..\opencv\modules\core\src\matrix.cpp, line 3197
Exception in thread "main" CvException [org.opencv.core.CvException: ..\..\..\..\opencv\modules\core\src\matrix.cpp:3197: error: (-215) A.size == arrays[i0]->size in function cv::NAryMatIterator::init
]
at org.opencv.core.Core.n_minMaxLocManual(Native Method)
at org.opencv.core.Core.minMaxLoc(Core.java:7919)
at com.example.globallocalmaxima_00.MainClass.main(MainClass.java:32)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-06 12:29:06.648283

Comments

hmm, no MatFactory, and no SysUtils here could you clarify, where you get that from ?

berak gravatar imageberak ( 2015-05-21 04:13:51 -0600 )edit

also, either don't use a Mask, or one with same size than the image (and rather give it valid content)

berak gravatar imageberak ( 2015-05-21 04:17:01 -0600 )edit

@berak MatFactory and SysUtils are my own classes i implemented. concering what you wrote in your second comments i really do not get it sorry..please let ne know how to get the local maxima in an image..regards

RB gravatar imageRB ( 2015-05-21 04:20:36 -0600 )edit

ok.

again, if you don't have a valid mask, use minMaxLoc(img); , not the one with the mask

berak gravatar imageberak ( 2015-05-21 04:26:34 -0600 )edit

@berak ok fine, but if i just used minMaxLoc(img) i will get the global maximum and minimum, while i am looking for the local Maxima.. i how my point is clréar and sorry for any inconviences

RB gravatar imageRB ( 2015-05-21 04:32:51 -0600 )edit
3

idea1:

 Core.minMaxLoc(gsMat.submat(y,y+3, x,x+3); // use a roi

idea2:

Mat mask = Mat.zeros(gsMat.size(), CV_8U); 
mask.submat(y,y+3,x,x+3).setTo(new Scalar(255)); // set some region to 'on'
Core.minMaxLoc(gsMat, mask)
berak gravatar imageberak ( 2015-05-21 04:48:42 -0600 )edit