forked from ivalab/grasp_multiObject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image2txt.m
65 lines (50 loc) · 2.05 KB
/
image2txt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
%% script to read a folder of images, and parse all imag file names into a single txt
%
%% read original image, crop it and save it in another folder
imgDataDir = 'rgd';
imgDataOutDir = 'rgd_cropped320';
imgRGBDataDir = 'rgbd';
imgRGBDataOutDir = 'rgb_cropped320';
imgFiles = dir([imgDataDir '/*.png']);
imgRGBFiles = dir([imgRGBDataDir '/rgb*']);
fileID_imgList = fopen([imgDataOutDir '/' 'testfull.txt'],'w');
for idx = 1:length(imgFiles)
display(['processing imgFiles ' int2str(idx)])
imgName = imgFiles(idx).name;
[pathstr,name] = fileparts(imgName);
img = imread([imgDataDir '/' name '.png']);
%imgCrop = imcrop(img, [207 127 226 226]);
imgCrop = imcrop(img, [161 81 320 320]);
imgResize = imresize(imgCrop, [227 227]);
imwrite(imgResize, [imgDataOutDir '/' name 'Cropped320.png']);
fprintf(fileID_imgList, '%s\n',[imgDataOutDir '/' name 'Cropped320.png']);
end
for idx = 1:length(imgRGBFiles)
display(['processing imgFiles ' int2str(idx)])
imgName = imgRGBFiles(idx).name;
[pathstr,name] = fileparts(imgName);
img = imread([imgRGBDataDir '/' name '.jpg']);
%imgCrop = imcrop(img, [207 127 226 226]);
imgCrop = imcrop(img, [161 81 320 320]);
imgResize = imresize(imgCrop, [227 227]);
imwrite(imgResize, [imgRGBDataOutDir '/' name 'Cropped320.png']);
end
%% read original grasp, according the cropping image, transform and save them in another folder
txtDataDir = './annotations';
txtDataOutDir = './rgd_cropped320';
txtFiles = dir([txtDataDir '/*.txt']);
for idx = 1:length(txtFiles)
display(['processing txtFiles ' int2str(idx)])
txtName = txtFiles(idx).name;
[pathstr,name] = fileparts(txtName);
fileID = fopen([txtDataDir '/' name '.txt'],'r');
sizeA = [2 inf];
A = fscanf(fileID, '%f %f', sizeA);
fclose(fileID);
name(3)='d';
fileID = fopen([imgDataOutDir '/' name 'Cropped320.txt'],'w');
%A = A - repmat([207 ;127 ],1, size(A,2));
A = (A - repmat([161 ;81 ],1, size(A,2)))*227/320;
fprintf(fileID, '%f %f\n',A);
fclose(fileID);
end