Saving Segmentation Result automatically - sprintf variable name

2 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by