How to read/ load .seg file ?

조회 수: 13 (최근 30일)
Ynne
Ynne 2018년 1월 4일
답변: Samay Sagar 2024년 9월 24일
I need to compare image segmentation result with ground truth wich is a .seg extenion file. How can I load this and create image groud truth. A part of the .seg file is shown below (I converted it to text file):
format ascii cr
date Thu Apr 26 17:39:26 2001
image 2092
user 1113
width 481
height 321
segments 9
gray 0
invert 0
flipflop 0
data
0 0 0 480
0 1 0 480
0 2 0 480
0 3 0 480
0 4 0 480
0 5 0 480
0 6 0 480
0 7 0 480
0 8 0 480
0 9 0 480
0 10 0 480
0 11 0 480
0 12 0 480
0 13 0 480
0 14 0 480
0 15 0 480
0 16 0 480
0 17 0 480
  댓글 수: 1
Adriana Royuela
Adriana Royuela 2024년 2월 13일
Hi! I have the same problem. How did you end up doing it?

댓글을 달려면 로그인하십시오.

답변 (1개)

Samay Sagar
Samay Sagar 2024년 9월 24일
You can parse the data from the segmentation file to extract relevant metadata and segmentation data. The parsed data can be used to create an image matrix. This matrix can be used to generate the ground truth image and can be used for comparison with the segmentation result.
You can use "fgetl" to read the SEG file line by line to extract the corresponding data. Based on the file shared by you, you can follow this approach to parse it:
function groundTruthImage = loadSegFile(filename)
% Open the file
fid = fopen(filename, 'r');
% Read the file line by line
tline = fgetl(fid);
while ischar(tline)
% Extract the width and height
if startsWith(tline, 'width')
width = sscanf(tline, 'width %d');
elseif startsWith(tline, 'height')
height = sscanf(tline, 'height %d');
elseif strcmp(tline, 'data')
break;
end
tline = fgetl(fid);
end
% Initialize the ground truth image
groundTruthImage = zeros(height, width);
% Read the segment data
while ischar(tline)
tline = fgetl(fid);
if ischar(tline)
data = sscanf(tline, '%d %d %d %d');
if numel(data) == 4
row = data(1) + 1;
colStart = data(3) + 1;
colEnd = data(4) + 1;
groundTruthImage(row, colStart:colEnd) = 1; % Assuming binary segmentation
end
end
end
% Close the file
fclose(fid);
end
groundTruthImage = loadSegFile('test.seg');
% Display the ground truth image
imshow(groundTruthImage);
% Now, you can compare this with your segmentation result
For more information, you can refer the following documentations:

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by