Skip to content

Codereview#2 of 1 (Garrido) from 14 (Romanello)#122

Open
Nintenking wants to merge 486 commits intoPrandiniUniPD:codereviewfrom
Nintenking:codereview#2_a
Open

Codereview#2 of 1 (Garrido) from 14 (Romanello)#122
Nintenking wants to merge 486 commits intoPrandiniUniPD:codereviewfrom
Nintenking:codereview#2_a

Conversation

@Nintenking
Copy link
Copy Markdown
Collaborator

Hi Stefano,
here is the code for the review. The methods I'd ask you to look at are:
-"BrightnessValue isBright(Mat imageMat)",

  • "Bitmap editBright(Bitmap image)";
  • "boolean isBlurred(Bitmap image)";
    All 3 of them are inside the class PreProcessing.java

I've also left in this pull request the whole ImageProcessing Module, perhaps you can more easily understand the methods this way.
Thank you for your time

frankplus and others added 30 commits December 8, 2018 15:19
ingredientsActivity is started from resultActivit in the menu.
Better visualization
showing  similarity
Sorting by similarity
Moved processing into a thread
Showing progress Dialog
moved button from menu into a floating action button in result activity
# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/unipd/se18/ocrcamera/AdapterTestAlterations.java
#	app/src/main/java/unipd/se18/ocrcamera/AdapterTestElement.java
#	app/src/main/java/unipd/se18/ocrcamera/PhotoTester.java
#	app/src/main/java/unipd/se18/ocrcamera/TestElement.java
Mat brightnessMat = new Mat();

//Changes the format of the matrix into a RGB one
Imgproc.cvtColor(imageMat, brightnessMat, Imgproc.COLOR_RGBA2RGB);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you did this for being able to split the color using the next few lines with Core.split right? Shouldn't be better to add this to the comment?

*/
private BrightnessValue isBright(Mat imageMat){
//Converts the image into a matrix
Mat brightnessMat = new Mat();
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change the name of this to something like rgbImageMat, in this way I know that I'm working with an RGB image.
Useful also because at line 193 reading the parameter of the switch I know that I'm working with an image

case CV_64F: bit = 64; break;
default: return BrightnessValue.IMAGE_IS_OK;
}
//Calculate the percentage of the brightness
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better description or documentation for what you are doing here should be useful to understand correctly this part of the code.

Imgproc.cvtColor(imageMat, brightnessMat, Imgproc.COLOR_RGBA2RGB);

//Obtain 3 different matrix with the 3 elemental colors
List<Mat> color = new ArrayList<>();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change this to imageColors. In this what I know that I'm working with the image that I want to work with and not with any other object containing colors

case CV_32S: bit = 32; break;
case CV_32F: bit = 32; break;
case CV_64F: bit = 64; break;
default: return BrightnessValue.IMAGE_IS_OK;
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BrightnessValue is an enum and BrightnessValue.IMAGE_IS_OK corresponds to 0.
The cases contain all the possible bits of an image, right? When I don't get one of them I return IMAGE_IS_OK but if there is an error in the image and opencv is not able to read its depth this is not correct because I can't know if the brightness of the image is really ok.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We understood that we'll always have 8 bit images so we are removing the switch

* @return the image with the modified brightness
* @author Thomas Porro(g1), Giovanni Fasan(g1), Oscar Garrido(g1)
*/
private Bitmap editBright(Bitmap image){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change the name of the method to something like "autoAdjustImageBrightness" because I would use "editBright" for methods where I have to tell the new brightness.

bright = IPUtils.conversionBitmapToMat(image);
} catch (ConversionFailedException error){
Log.e(TAG, error.getErrorMessage());
return image;
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to return null in this case and manage the exception from where you call editBright() or create a custom exception because is not correct to return an image even if it doesn't have been processed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought to create a different object that contains both the image and the TAG, saying if the image was analyzed or not

return IPUtils.conversionMatToBitmap(modifiedMat);
} catch (ConversionFailedException error){
Log.e(TAG, error.getErrorMessage());
return image;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as line 244

return IPUtils.conversionMatToBitmap(modifiedMat);
} catch (ConversionFailedException error){
Log.e(TAG, error.getErrorMessage());
return image;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as line 244

final int step = 15;

//Converts the image into a matrix
Mat bright;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change the name of this object to "imageMap" because as is I can't understand that I'm working with the image

case IMAGE_TOO_BRIGHT:
Log.d(TAG, "Case==IMAGE_TOO_BRIGHT");
//Darkens the colour's brightness until it's in an optimal value
for(double changeBrightness = 0; changeBrightness != maxBrightness;
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood but In this way I can end to an infinite loop (avoided by
if(isBright(modifiedMat) == BrightnessValue.IMAGE_IS_OK)) , changeBrightness is always different from maxBrightness. I suggest to add a minBrightness=-240 value for example and use
for(double changeBrightness = 0; changeBrightness >= minBrightness ; changeBrightness -= step)
What do you think?

Log.d(TAG, "Case==IMAGE_TOO_DARK");
//The variables are explained in the case above
//Lightens the colour's brightness until it's in an optimal value
for(double changeBrightness = 0; changeBrightness != maxBrightness;
Copy link
Copy Markdown
Collaborator

@stefanoromanello stefanoromanello Jan 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I misunderstood also here but In this way I can end to an infinite loop (avoided also here by
if(isBright(modifiedMat) == BrightnessValue.IMAGE_IS_OK)).
I suggest to use
for(double changeBrightness = 0; changeBrightness <= maxBrightness; changeBrightness += step)
What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are making the switch smaller and avoiding the for cycles

int maxLap = -16777216;

//Threshold above which the color is out of focus
final int threshold = -6118750;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change the name of this to outOfFocusThreshold for a more clear idea of what this is variable is for

imageMat = IPUtils.conversionBitmapToMat(image);
} catch (ConversionFailedException error){
Log.e(TAG, error.getErrorMessage());
return false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why returning false if the image has not yet been processed? I suggest to return null in this case and manage the exception from where you call isBlurred() or create a custom exception.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We created an enum to manage the different situations

laplacianImage = IPUtils.conversionMatToBitmap(laplacianMat8Bit);
} catch (ConversionFailedException error){
Log.e(TAG, error.getErrorMessage());
return false;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as line 336

public boolean isBlurred(Bitmap image) {

//Total number of color
int maxLap = -16777216;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to add to the comment why you are instantiating this to -16777216

);

//Searches the pixel that has the highest colour range in the RGB format
for(int pixel : pixels){
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this part. What are the integer values inside pixels[]?? The brightness of each pixel or a special value obtained using the laplacianImage? At the end of the for cycle maxLap what contains? The brightest pixel?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We read in various articles that a way to estimate the sharpness of an image is to apply a Laplace filter and then pick the maximum value. I'll add this information as a comment in the code

Mat greenLuminance= new Mat();
Core.multiply(color.get(1), new Scalar(0.7152), greenLuminance);
Mat blueLuminance = new Mat();
Core.multiply(color.get(2), new Scalar(0.0722), blueLuminance);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to create constant variables for these values

@Nintenking
Copy link
Copy Markdown
Collaborator Author

Should be ok now, if you think it is correct could you close the pull request so we can merge the module in the Demo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants