cocoaimagehashing
cocoaimagehashing copied to clipboard
Can I use that to make a groups of similar images from source array?
@vadimkklim from what you want to make a group? If you can explain more I think I can help you.
@kuls14 i am using "[[OSImageHashing sharedInstance] similarImagesWithHashingQuality:" to find similar images in photo library but it work only for copies of images. If images slightly different it will never find them. Maybe you can help how to setup accuracy?
I am requesting 100x100 imgage from PHImageManager, convert it to Data by "pngData" and apply "medium quality" from OSImageHashing
@kuls14 okay, i was trying also to convert image to 8x8 size, move it to grayscale but results became even badder
extension UIImage {
var noir: UIImage? {
let context = CIContext(options: nil)
guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else { return nil }
currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey)
if let output = currentFilter.outputImage,
let cgImage = context.createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation)
}
return nil
}
}
Yes
On 26 Jul 2019, at 11:14, Kuldip Soliya [email protected] wrote:
Are you trying to get photos from PHAssets?
On Fri 26 Jul, 2019, 12:02 AM Igor Bizi, [email protected] wrote:
@kuls14 https://github.com/kuls14 okay, i was trying also to convert image to 8x8 size, move it to grayscale but results became even badder
extension UIImage { var noir: UIImage? { let context = CIContext(options: nil) guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else { return nil } currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey) if let output = currentFilter.outputImage, let cgImage = context.createCGImage(output, from: output.extent) { return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation) } return nil } }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=AJHDKB7N34RQCRH54ZUHQ43QBHWUXA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD22MFTY#issuecomment-515162831, or mute the thread https://github.com/notifications/unsubscribe-auth/AJHDKB6TZX7OTH4FDHLMDVLQBHWUXANCNFSM4IFQXQ4Q .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Sounds great, thank you
On 26 Jul 2019, at 11:27, Kuldip Soliya [email protected] wrote:
I'll send you my code in 45 to 60 minutes so you can see what I have done and can implement same. I have very satisfactory results.
On Fri 26 Jul, 2019, 8:55 AM Igor Bizi, [email protected] wrote:
Yes
On 26 Jul 2019, at 11:14, Kuldip Soliya [email protected] wrote:
Are you trying to get photos from PHAssets?
On Fri 26 Jul, 2019, 12:02 AM Igor Bizi, [email protected] wrote:
@kuls14 https://github.com/kuls14 okay, i was trying also to convert image to 8x8 size, move it to grayscale but results became even badder
extension UIImage { var noir: UIImage? { let context = CIContext(options: nil) guard let currentFilter = CIFilter(name: "CIPhotoEffectNoir") else { return nil } currentFilter.setValue(CIImage(image: self), forKey: kCIInputImageKey) if let output = currentFilter.outputImage, let cgImage = context.createCGImage(output, from: output.extent) { return UIImage(cgImage: cgImage, scale: scale, orientation: imageOrientation) } return nil } }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=AJHDKB7N34RQCRH54ZUHQ43QBHWUXA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD22MFTY#issuecomment-515162831 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AJHDKB6TZX7OTH4FDHLMDVLQBHWUXANCNFSM4IFQXQ4Q
.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=AJHDKB2YUHPBTGWGR3KA7ZDQBJVCLA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD23MGVA#issuecomment-515294036, or mute the thread https://github.com/notifications/unsubscribe-auth/AJHDKBYS3QXM6SNUMGVS6JDQBJVCLANCNFSM4IFQXQ4Q .
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=ABOZHCS4FA3GMNHBBT5HPKDQBJVIJA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD23MISA#issuecomment-515294280, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOZHCQMFYF44GRPHUYCDADQBJVIJANCNFSM4IFQXQ4Q.
I am using this to get image from PHAssets
import Foundation
import Photos
extension PHAsset {
/// To get Thumbnail image from PHAssets
var image : UIImage {
var thumbnail = UIImage()
let imageManager = PHCachingImageManager()
let options = PHImageRequestOptions()
options.version = .current
// options.deliveryMode = .opportunistic
let scale = UIScreen.main.scale
let size = CGSize(width: 50.0 * scale, height: 50.0 * scale)
// let size = CGSize(width: 100.0, height: 100.0)
imageManager.requestImage(for: self, targetSize: size, contentMode: .aspectFill, options: nil) { (image, info) in
thumbnail = image!
}
return thumbnail
}
}
and for comparison I use
let similarImageIdsAsTuples = OSImageHashing.sharedInstance().similarImages(with: OSImageHashingQuality.high, forImages: images)
This will return tuples so I have use below method to get group of similar image in array so I can display it in tableview or collection view.
func findDuplicateImage() {
var images: [OSTuple<NSString, NSData>] = []
for i in 0..<arrAllImage.count {
let imgData = arrAllImage[i].image.pngData()!
images.append(OSTuple<NSString, NSData>(first: NSString(string: "\(i)"), andSecond: imgData as NSData))
}
//
let similarImageIdsAsTuples = OSImageHashing.sharedInstance().similarImages(with: OSImageHashingQuality.high, forImages: images)
var arrayID = [[NSString]]()
for tuple in similarImageIdsAsTuples {
let id = [tuple.first!, tuple.second!]
arrayID.append(id)
}
var resultArray = [[NSString]]()
for (i,arrayI) in arrayID.enumerated() {
DispatchQueue.main.async {
self.lblNumberOfPhoto.text = R.string.localizable.processing_similar_photos_number("\(i)", "\(arrayID.count)")
}
if i == 0 {
resultArray.append(arrayI)
} else {
var isContains = false
for (j,result) in resultArray.enumerated() {
if result.contains(arrayI[1]) && result.contains(arrayI.first!) {
isContains = true
break
} else if result.contains(arrayI.first!) {
var newdata = result
resultArray.remove(at: j)
newdata.append(arrayI[1])
resultArray.insert(newdata, at: j)
isContains = true
break
} else if result.contains(arrayI[1]) {
var newdata = result
resultArray.remove(at: j)
newdata.append(arrayI.first!)
resultArray.insert(newdata, at: j)
isContains = true
break
}
}
if !isContains {
resultArray.append(arrayI)
}
}
}
arrDupliImage.removeAll()
for similarImageID in resultArray {
var dupliImageTabel = [DuplicateImage]()
for imgId in similarImageID {
let data = arrAllImage.filter { (dupImg) -> Bool in
return dupImg.id == imgId.integerValue
}
if !data.isEmpty {
dupliImageTabel.append(data.first!)
}
}
arrDupliImage.append(dupliImageTabel)
}
}
Please try to use 150*150 as max size for image otherwise it may cause memory issue.
Thanks for the code, I use kind of the same. Do you use it in some app? Comparing to SmartCleaner this library is 100x slower. Looks like they use some kind of machine learning or vision to make comparison super fast the precise ...
On 26 Jul 2019, at 12:10, Kuldip Soliya [email protected] wrote:
I am using this to get image from PHAssets
import Foundation import Photos
extension PHAsset { /// To get Thumbnail image from PHAssets var image : UIImage { var thumbnail = UIImage() let imageManager = PHCachingImageManager() let options = PHImageRequestOptions() options.version = .current // options.deliveryMode = .opportunistic let scale = UIScreen.main.scale let size = CGSize(width: 50.0 * scale, height: 50.0 * scale) // let size = CGSize(width: 100.0, height: 100.0)
imageManager.requestImage(for: self, targetSize: size, contentMode: .aspectFill, options: nil) { (image, info) in thumbnail = image! } return thumbnail }
} and for comparison I use
let similarImageIdsAsTuples = OSImageHashing.sharedInstance().similarImages(with: OSImageHashingQuality.high, forImages: images)
Please try to use 150*150 as max size for image otherwise it may cause memory issue.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=ABOZHCRRHKPCWAYQMYNKIMDQBJ2KXA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD23OAJY#issuecomment-515301415, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOZHCQ5WVPOL5SHYVJGF5LQBJ2KXANCNFSM4IFQXQ4Q.
Yes smartClearner is definitely fast and more accurate for duplicate contacts too.
Do you have any idea what technology they can use? I am making similar app, but want similar quality
On 26 Jul 2019, at 13:51, Kuldip Soliya [email protected] wrote:
Yes smartClearner is definitely fast and more accurate for duplicate contacts too.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ameingast/cocoaimagehashing/issues/19?email_source=notifications&email_token=ABOZHCX35SGF5AM7TW3NXRDQBKGHXA5CNFSM4IFQXQ42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD23SJNI#issuecomment-515318965, or mute the thread https://github.com/notifications/unsubscribe-auth/ABOZHCQ36DPGPNWU27BTUBLQBKGHXANCNFSM4IFQXQ4Q.
@bizibizi Hey. did you find a better solution?