Problem to Read .txt file

1 回表示 (過去 30 日間)
Akmal Rahmat
Akmal Rahmat 2014 年 11 月 21 日
コメント済み: Akmal Rahmat 2014 年 11 月 21 日
Hello all.. I have problem to read my .txt file. I already convert my image to .txt file. My image size is 100x100. How to read it and use it in for loop ? here is my coding to change to image to .txt file.
a = imread('img2.jpg');
b = imresize(a,[100,100])
dlmwrite('test4.txt', b, 'delimiter', ',');
d = dlmread('test4.txt');
[x,y] = size(d);
i want to make comparison between two .txt file.That is why i need to read the .txt file.
  2 件のコメント
Thorsten
Thorsten 2014 年 11 月 21 日
OK. But what exactly is your problem?
Akmal Rahmat
Akmal Rahmat 2014 年 11 月 21 日
First , i insert the image then i save it into .txt file (this is for the test image). Then i want to compare the test image with another image which already save in .txt file also. So in .txt file(test image) i got hundreds of columns and rows of number, and i want to compare each one of the number in .txt file with another .txt file. That why i want to know the proper way to read the .txt file. Below is the code on how i want to compare between both .txt file. i dont even know if it can work. and sorry for my english. Please give me some guidance.
for (int d=0;d<100;d++)
{ for(int g=0;g<100;g++)
{ pixel1 = img1[d][g];%rows
pixel2 = img2[d][g];%column
fpixel = pixel1-pixel2;
if fpixel<=125
{ fpixel = 1;
return 1; }
else fpixel>125
{ fpixel = 0;
return 0; }
}
}
i dont even know my coding is right or not. sorry.

サインインしてコメントする。

採用された回答

Thorsten
Thorsten 2014 年 11 月 21 日
編集済み: Thorsten 2014 年 11 月 21 日
You probably should first have a look at your .txt file to check if is has reasonable values, all separated by commas (or blanks, other delimiters may alos work)
type test4.txt
If this is ok, you can read the files using
T1 = dlmread('testimage.txt');
T2 = dlmread('anotherimage.txt')
and compute the difference image (no need to use for-loops)
D = T1 - T2;
and find the nonzero entries
ind_nonzero = find(D~=0);
  1 件のコメント
Akmal Rahmat
Akmal Rahmat 2014 年 11 月 21 日
thank you thorsten

サインインしてコメントする。

その他の回答 (1 件)

Luuk van Oosten
Luuk van Oosten 2014 年 11 月 21 日
This might help to open your .txt file.
  1 件のコメント
Akmal Rahmat
Akmal Rahmat 2014 年 11 月 21 日
i'll look into it. Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by