Saving Segmentation Result automatically - sprintf variable name

2 ビュー (過去 30 日間)
ana ain
ana ain 2016 年 4 月 5 日
コメント済み: Adam 2016 年 4 月 5 日
I want to save the segmentation result for every word images in sequential format.
Word images:
The segmentation process, will give multiple images as output for every segmented character. Word images contain various amount of character, so the output also will vary. For example, Output of segmented result for image = data(1).png become data(1)_1.png, data(1)_2.png, data(1)_3.png, and data(2).png become data(2)_1.png, data(2)_2.png, data(2)_3.png, data(2)_4.png and so on.
I've tried this code:
% Save %
[L,num] = bwlabel(im);
for z= 1 : num
bw= ismember( L, z);
% Construct filename for this particular image.
baseFileName = sprintf('data.%d.png', y);
y=y+1;
% Prepend the folder to make the full file name.
fullFileName = fullfile(myFolder, baseFileName);
% Do the write to disk.
imwrite(bw, fullFileName);
subplot(2,2,4);
pause(1);
imshow(bw);
end
% y=y+1;
after using the code, it create a good result, but just for one data, the next data will replace the recent data. So, lately, for every word image, I run the segmentation process one by one for each word images and change this part to get an appropriate result. Change sprintf('data (1).%d.png', y) to become sprintf('data (2).%d.png', y); and so on.
% Change basefilename for each word images %
baseFileName = sprintf('data (1).%d.png', y);
y=y+1;
The expected result:
I hope I can do it automatically, so it could be more effective and reliable for bigger data set.
Any suggestion would be very appreciated. Thank you.

回答 (1 件)

Adam
Adam 2016 年 4 月 5 日
baseFileName = sprintf('data (%d).%d.png', z, y);
seems like it should work.
  2 件のコメント
ana ain
ana ain 2016 年 4 月 5 日
z represent for? could you explain more about the code.
Adam
Adam 2016 年 4 月 5 日
Your code currently sits inside a for loop and z is the loop variable you used. Unless I am misunderstanding it this is the value that should go in the brackets in your naming convention.

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

カテゴリ

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