Naming with count number in Matlab - matlab

FileName = fullfile('C:\Users\User\Desktop\1cm circle cropped 0.27',sprintf('circle_cropped_%d.jpg',count));
The code I use would give file name
(circle_cropped_1.jpg, circle_cropped_2.jpg, circle_cropped_3.jpg.........)
How to name the images with "circle_cropped_001.jpg, circle_cropped_002.jpg, circle_cropped_003.jpg.........................."
And how to move the counting number? to be "001_circle_cropped.jpg, 002_circle_cropped.jpg, 003_circle_cropped.jpg......................."

FileName = fullfile('C:\Users\User\Desktop\1cm circle cropped 0.27',sprintf('%03d_circle_cropped.jpg',count));
Assuming you want a total field width of 3. If you want more, specify %04d or %05d etc, the prefix 0 there ensures the desired string width is filled by padding with zeros.

Related

Label file of yolov7

I downloaded the object model yolov7 (https://github.com/WongKinYiu/yolov7) and the coco dataset. Then there are the folders coco\images and coco\labels.
I opened the image "coco\images\train2017\000000000034.jpg" and the corresponding label file "coco\labels\train2017\000000000034.jpg".
An annotation for the yolo-model has to be in the form:
<object_class> <x_center> <y_center>
The content of the label file is:
22 0.00746875 0.0539294 0.117891 0.0921412
0.231297 0.110118 0.2895 0.0674118
0.331281 0.0472 0.3865 0.0696706
0.423813 0.0943765 0.446188 0.105624
0.467078 0.1528 0.517813 0.182024
0.577516 0.253929 0.658094 0.379765
0.690922 0.532588 0.687937 0.6
0.650625 0.555059 0.658094 0.644941
0.668547 0.755059 0.676 0.838212
0.658094 0.894376 0.613328 0.925835
0.589453 0.914612 0.590938 0.856188
0.552141 0.791012 0.523781 0.725835
0.528266 0.633718 0.498422 0.577529
0.444703 0.505624 0.407391 0.505624
0.395453 0.541576 0.417844 0.591012
0.450672 0.642706 0.456641 0.642706
0.461109 0.725835 0.458125 0.786518
0.450672 0.853929 0.444703 0.898871
0.401422 0.869671 0.411875 0.815741
0.423813 0.734824 0.425297 0.694376
0.361125 0.608988 0.316359 0.588753
0.280547 0.703365 0.271594 0.757294
0.261141 0.829224 0.268609 0.869671
0.277562 0.901129 0.250703 0.937082
0.222344 0.939318 0.231297 0.901129
0.222344 0.844941 0.238766 0.7236
0.246219 0.642706 0.271594 0.510118
0.182062 0.507859 0.0999844 0.525835
0.0208906 0.494376 0.0015 0.0516941
For what all numbers stand for?
I think you downloaded the segmentation dataset.
Go in the cloned yolov7 directory and run
bash scripts/get_coco.sh
to get the object detection dataset
The number looks like normalized values for the segmentation of the image. The first number corresponds to the class label, and the point makes a mask for the object detected
Segmentation draw a mask around the object. So the numbers above represent the coordinates for the mask. Similar to bounding box but bounding box have 4 values (x, y, width, height), a segmentation have a mask. The number of points in a mask are not always same in number so you will see different number of points for different object or even for same object. Masks in the image above you can see that there are bounding boxes with masks. so each value represent a point of the mask

how to let long text change to multiple lines when adding annotation to images

how to let long text change to multiple lines when adding annotation to image
and make the length of each line are equal, like rectangle?
image temp:=getfrontimage()
temp.ShowImage()
imageDisplay disp = front.ImageGetImageDisplay(0)
getsize(temp,x,y)
le=x*2/3
to1=y*80/100
component text1 = NewTextAnnotation(le,to1,string1+","+string2+","+string3,100)
I tried to add 3 strings to an image, each string has more than 15 letters/characters, Total more than 50 letters.
If I put all 3 strings in one text annotation in on line, it is too long.
If I put them as 3 text annotations, as the each line does not have exactly same numbers of letters, it shows ugly.
Is there any could let the text as multiple line, and the background of texts in each line has the same length?
Or the 3 text annotations has the same length, I mean the background of the texts has the same length, when the letters in each text annotations are not same, for example, 1st text annotation with 16 letters, 2nd text annotation with 20 letters, 3rd text annotation with 14 letters, but their background of the text have the same length.
Thanks,
You can add line-breaks as with all strings by simply adding the line-break escape string \n.
Example script:
number sx = 512
number sy = 512
image img := RealImage("test",4,sx,sy)
img = icol
img.ShowImage()
imageDisplay disp = img.ImageGetImageDisplay(0)
number l = sx * 2/3
number t = sy * 80/100
String mLstr = "Some text line\nSome more text lines\nShort text"
number fontSize = 12
Component Line = disp.NewTextAnnotation(l,t,mLstr,fontSize)
Line.TextAnnotationSetAlignment(1) // 1=Left, 2=Center, 3=Right
Line.ComponentSetDrawingMode(1) // 1=with background, 2=without background
Line.ComponentSetBackgroundColor(0.5,0.0,0)
Line.ComponentSetForegroundColor(0,1,0)
disp.ComponentAddChildAtEnd(line)
A note: When creating the new component, there are two different variants of the NewTextAnnotation command:
Component NewTextAnnotation( Component ref_par_comp, Number left, Number top, String text, Number size )
Component NewTextAnnotation( Number left, Number top, String text, Number size )
The first one takes the addtional "parent" component. If you use that one, then the font-size will scale with the default display-size of the parent component on the screen, i.e. will not be different for differently sizes images.
To test: Just try the above script with sx and sy values. Then do the same without the disp. in the line-annotation creating line.

Relative UILabel in a game object

I created a game object which acts as a repeating item for a UIGrid which I populate dynamically. The gameobject (RowItem) has couple of UILabel whose text can change on runtime depending on the content. The content of these UILabels overlap when the text is bigger. Can anybody help me in how to make UILabel expand relative to the adjacent UILabel when the text is more/less?
You can use transform.localScale property of the UILabel's property to scale it. Just make them bigger when the text is bigger than let's say 20 characters. Try with arbitrary values.
Also when you change the scale, run a re-align method, which aligns other labels so that they don't overlap.
you can get the text length in pixel by this:
UILabel label;
float width = label.relativeSize.x * label.transform.localScale.x;
float height = label.relativeSize.y * label.transform.localScale.y;
Let's say that you want to set you max length to 100, you can do this:
if (width > 100)
{
label.localScale = new Vector3(100 / label.relativeSize.x, 100/ label.relativeSize.x, 1);
}
the second param for Vector3 is also based on relativeSize.x is not a typo, that makes sure your text will not become thin.
Hope this works.

How to count line breaks (not /n) in an UITextView?

I would like to count how many automatic line breaks (not returns the user enters) I have in a text displayed in UITextView which is, for argument's sake, 200 pixels in width and 460 pixels in length (see attached screen shot!).
I have found this when looking for a solution:
stringSize = [t sizeWithFont:f constrainedToSize:CGSizeMake(320, 10000)
lineBreakMode:UILineBreakModeWordWrap];
But this won't give me an int number for 'invisible' line brakes, will it? Also, I don't understand the 320, 10000 ... 320 is for the width I guess and would need to be changed to 200 in my case. But why 10.000 ??
Sorry, but I'm a beginner and this doesn't make much sense to me...
The CGSizeMake statement is to provide bounds in order to compute the size of text. It is common to constrain the width and to set a high value for the height to let enough space for the computation.
In your case, the width will be 200 and you can leave the height to 10000 as long as the text is not too long.

Split String at specific line for NSString

Hello ist there a way to split a String for UITableView at a specific line to put the "rest" (the second part of the data) in an own cell
NSString *data;
CGsize *size = [data sizeOfStringWithFont:[UIFont systemFontOfSize:14] constrainToWidth:280.0];
if the size.height e.g. is greater than 1500 i want to split the string at this line position!
thank you
Use "constrainedToSize" (instead of just to width) and render as much as you can.
If you really want to take exactly the text that would not fit, you're going to have to do essentially a search, adding a word at a time and then doing the size check to see how high you have gotten. You could start out with a rough estimate by doing the whole string constrained to something only one line high with boundless width (say 999999) and then divide up the width into however many rows you are wishing to allow to get a rough starting point for adding/removing words from the string (it will not be exact because of word wrapping).
Fundamentally though it seems wierd to take the leftover text and put it in another cell. Are you really sure you don't simply want to change the height of the cell with the text to allow it to fit the whole thing?
I think Kendall has the right idea, but the constrained sizes should be reversed to get the exact height based on word wrapping. Take a sample CGSize that is the same width as your cell, but with a height larger than the max height you expect. In the sample code below, textSize will contain the height of your string as it would appear in your cell with an unbounded height.
CGSize sz = CGSizeMake (
yourCellWidth,
999999.0f );
CGSize textSize = [yourString sizeWithFont:yourCellfont
constrainedToSize:sz
lineBreakMode:UILineBreakModeWordWrap];
If the height is greater than 1500, you could start picking off substrings (substringWithRange) from the end and measuring them like above until you get something >= the remainder above 1500 that was returned by textSize.