Objective C Comparing the name of an UIImageView - iphone

i have a question, totally newbie but i would like to know how can i get to compare and image in an if else statement?
i have an image lets say it is "img.png" and i have it displayed in an imageview already in the application, however in the codes i would like to compare if the image show is "img.png"
I understand that for string we use the isEqualToString:, so if it's for an image what would i use?
example would be :
if ([img.image isEqual:#"img.png"])
What i've typed is something like this but it isnt working. could anyone point me in the right direction? thanks alot
Much appreciated!

If you first got the image using [UIImage imageNamed:#"img.png"] you could compare the image object pointers: if (img.image == [UIImage imageNamed:#"img.png"]).
But: I'd consider this bad design and would rather use another way of identifying images, like storing the name of the image in another instance variable.

Related

UIImage unrecognized selector sent to instance

I have the 'classic' error:
unrecognized selector sent to instance.
If I read through other comparable questions it should be memory related, however I can't find out what I'm doing wrong.
Here is what I try to do:
crop an image
give the image rounded corners
I use the brilliant code of Trevor
This is my code:
The roundedCornerImage:borderSize: is giving the trouble
NSInteger my_borderSize = 0.1;
UIImage *Image_large = [image_sel croppedImage:CGRectMake((my_width/2) -(my_height*0.66)/2, 0, my_height*0.66, my_height) ];
UIImage *roundedCornerImage_temp = [Image_large roundedCornerImage:0.8 borderSize:my_borderSize];
That method is not in Apple's UIImage class. They are extensions to UIImage written by the guy whose code you link to.
You need to make sure to add UIImage+RoundedCorner.h and UIImage+RoundedCorner.m to your Xcode project, and then in the class where you want to use roundedCornerImage:borderSize:, you should
#import "UIImage+RoundedCorner.h"
Also, I notice that you're passing in decimal values for both cornerSize and borderSize. Those are supposed to be NSInteger values, per Trevor's API. I would guess that those are in display points, but apparently, he limited it to integer values.
Update: also make sure that the UIImage+RoundedCorner.m file is listed among your Compile Sources:

Texture feature extraction using Gray Level Cooccurence Matrix

I'm doing a project in liver tumor classification. I used this code and it gave some output. I don't know whether I'm correct.
Actually I initially used Region Growing method for liver segmentation and from that I segmented tumor using FCM. So, to this GLCM program, I gave the tumor segmented image as input. Was I correct? If so, I think, then, my output will also be correct.
I gave the parameters exactly as in the example. Actually what do they mean? Do I need to change them for different images? If so, how to give the parameters? I'm completely new to this. So, kindly guide me.
I got this output. Am I correct?
stats =
autoc: [1.857855266614132e+000 1.857955341199538e+000]
contr: [5.103143332457753e-002 5.030548650257343e-002]
corrm: [9.512661919561399e-001 9.519459060378332e-001]
corrp: [9.512661919561385e-001 9.519459060378338e-001]
cprom: [7.885631654779597e+001 7.905268525471267e+001]
cshad: [1.219440700252286e+001 1.220659371449108e+001]
dissi: [2.037387269065756e-002 1.935418927908687e-002]
energ: [8.987753042491253e-001 8.988459843719526e-001]
entro: [2.759187341212805e-001 2.743152140681436e-001]
homom: [9.930016927881388e-001 9.935307908219834e-001]
homop: [9.925660617240367e-001 9.930960070222014e-001]
maxpr: [9.474275457490587e-001 9.474466930429607e-001]
sosvh: [1.847174384255155e+000 1.846913030238459e+000]
savgh: [2.332207337361002e+000 2.332108469591401e+000]
svarh: [6.311174784234007e+000 6.314794324825067e+000]
senth: [2.663144677055123e-001 2.653725436772341e-001]
dvarh: [5.103143332457753e-002 5.030548650257344e-002]
denth: [7.573115918713391e-002 7.073380266499811e-002]
inf1h: [-8.199645492654247e-001 -8.265514568489666e-001]
inf2h: [5.643539051044213e-001 5.661543271625117e-001]
indnc: [9.980238521073823e-001 9.981394883569174e-001]
idmnc: [9.993275086521848e-001 9.993404634013308e-001]
Kindly guide me. Thank you
its ok but i don't think we usually need all this extra information i usually prefer to use the following code
GLCM2 = graycomatrix(img,'Offset',[1 1]);
stats = graycoprops(GLCM2);
i hope it will help you

How to avoid image duplication in image gallery of iOS device?

I want to store the images to photo gallary. But if images are already available at photo gallary then how to distinguish for whether imgaes are already exists or not? I didnt find property like unique identifier or should i compare by taking data in the form of NSdata?
thanks..
You can maintain a dictionary of hashes for each the image in the photo gallery, and then show only additional images who do not hashes are not present in the dictionary
As a reminder, you can check for an object in a dictionary by doing:
if ([myDictionary objectForKey:variableStoringImageHash] == nil) {
//No such image present
}
else {
//image is present
}
For a bit about hashing an image, this might help:
iPhone: fast hash function for storing web images (url) as files (hashed filenames)
I am not sure if what eitan27 says will work so as an alternative I would say that your best hope is comparing NSData objects. But this as you can see will become very tedious as there will be n number of images in library and comparing each one for repetition does't make sense , still if you want to compare data you look at this answer which will give you a fraction of how much the data is matching.

Get cropped photo of person in MonoTouch (on iPhone)

I'm able to get original image of person from address book but I would like to ask, if there is any way how to get cropped image (in case, user has taken a picture and zoomed just some part of it). I found a way, how to do this in objective-c:
NSData *imageData = [(NSData *)ABPersonCopyImageDataWithFormat(
recordRef, kABPersonImageFormatThumbnail) autorelease];
I can't find a way how to get this thumbnail in MonoTouch. I found just this enumeration which has definitely something to do with that, but nothing else :(
http://docs.go-mono.com/MonoTouch.AddressBook.ABPersonImageFormat/Members
Please, has anybody any idea?
Thanks in advance
Try MonoTouch.AddressBook.ABPerson.Image propery. And MonoTouch.AddressBook.ABPerson.HasImage property to shure that MonoTouch.AddressBook.ABPerson has a picture.
When you right-click on the Image property of an ABPerson instance and then select 'Go to declaration', you will find the code Monotouch implements for this property:
public NSData Image {
get {
return (NSData)Runtime.GetNSObject(ABPerson.ABPersonCopyImageData(this.Handle));
}
set {
if (!ABPerson.ABPersonSetImageData(this.Handle, (value ? value.Handle : IntPtr.Zero), &IntPtr ))
{
throw CFException.FromCFError();
}
}
}
You see that a ABPerson.ABPersonCopyImageData method is used to return the Image, so there is a method to get the image, but I think it is marked Internal.
So I think we need to Bind the Objective C functions ourself. Is there anybody out there who knows how to do this or has any experience with this?

Change file names of images?

I want to change the file names of images in my app, can i do this?
If the image is inside your NSBundle, then the answer is No. If you copy an image from ALAssetsLibrary you can name it whatever you like.
If it is in your NSBundle and you'd like to create a copy of the same image name, you can do that by loading the NSData and saving it with a different name. That just uses up extra space though.
Why are you trying to change the name of an image to begin with? If you needed to, you can create an NSMutableDictionary and a special function which takes a "filename" and returns the name of the actual image file in your NSBundle.
For example if you had a file named "MyImage.png" which part of your program thinks is actually called "ThatCoolPicture.png", you can load it like this:
UIImage *img = [UIImage imageNamed:[self nameForPseudoname:#"ThatCoolPicture.png"]];
In this case nameForPseudoname takes a "nickname" and returns the real name.
Hope this helps!