Android Question How to do HDR image processing?

Inman

Well-Known Member
Licensed User
Longtime User
VYQtbWR.jpg


HDR or High Dynamic Range, as its name implies, is a method that aims to add more "dynamic range" to photographs, where dynamic range is the ratio of light to dark in a photograph. Instead of just taking one photo, HDR uses three photos, taken at different exposures and combines them. You can read more about HDR here.

https://lifehacker.com/5991508/what-is-hdr-and-when-should-i-use-it-in-my-photos

I was wondering how we can do HDR processing to a photo. To be clear, I don't want to take a photo within my app using HDR mode. I want to apply HDR effect to an existing photo.

I found a couple of image processing libraries that have HDR included in them.

https://android-arsenal.com/details/1/298
https://github.com/alhazmy13/ImageFilters

Also a stackoverflow post that tries to explain the logic behind HDR algorithm.

https://stackoverflow.com/questions/11115278/how-does-hdr-worked-how-to-make-hdr-effect

Hopefully someone will be able to come with a solution for B4A.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Here you go....have only wrapped the HDRFilter of https://github.com/alhazmy13/ImageFilters. Can add the others if required.

Copy the attached jar and xml to your additional libs folder.

Sample Code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aImageFilters
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region


#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private iv1 As ImageView
    Private iv2 As ImageView
    Private bm As Bitmap
    
    Private imfil As ImageFilters
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    
    bm.Initialize(File.DirAssets, "original.jpg")
    iv1.Bitmap = bm
    
    iv2.Bitmap = imfil.applyHDRFilter(bm)
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




1.png
 

Attachments

  • ImageFilters.jar
    278.1 KB · Views: 314
  • ImageFilters.xml
    696 bytes · Views: 302
  • b4aImageFilters.zip
    23.1 KB · Views: 315
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
This is version 1.01
Copy the jar and xml to your additional libs folder (have only wrapped the filters that don't require additional parameters to be passed - you can do the rest of them. Use the attached Java code to add the filters where additional params other than the Bitmap have to be passed).

2.png


Sample Code (9 different filters):
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aImageFilters
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region


#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private iv1, iv2, iv3, iv4, iv5, iv6, iv7, iv8, iv9, iv10 As ImageView
    
    Private bm As Bitmap
    
    Private imfil As ImageFilters
    

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    
    bm.Initialize(File.DirAssets, "original.jpg")
    iv1.Gravity = Gravity.FILL
    iv1.Bitmap = bm
    
    iv2.Gravity = Gravity.FILL
    iv2.Bitmap = imfil.applyHDRFilter(bm)
    
    iv3.Gravity = Gravity.FILL
    iv3.Bitmap = imfil.applyTvFilter(bm)
    
    iv4.Gravity = Gravity.FILL
    iv4.Bitmap = imfil.applyBlockFilter(bm)
    
    iv5.Gravity = Gravity.FILL
    iv5.Bitmap = imfil.applyGothamFilter(bm)
    
    iv6.Gravity = Gravity.FILL
    iv6.Bitmap = imfil.applyInvertFilter(bm)
    
    iv7.Gravity = Gravity.FILL
    iv7.Bitmap = imfil.applyOldFilter(bm)
    
    iv8.Gravity = Gravity.FILL
    iv8.Bitmap = imfil.applyReliefFilter(bm)
    
    iv9.Gravity = Gravity.FILL
    iv9.Bitmap = imfil.applySharpenFilter(bm)
    
    iv10.Gravity = Gravity.FILL
    iv10.Bitmap = imfil.applySketchFilter(bm)
    
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

Attachments

  • b4aImageFilters.zip
    23.5 KB · Views: 305
  • ImageFilters.jar
    278.3 KB · Views: 322
  • ImageFilters.xml
    3 KB · Views: 364
  • TheJavaCode.zip
    14.4 KB · Views: 344
Upvote 0
Top