How to read/ load .seg file ?

7 visualizzazioni (ultimi 30 giorni)
Ynne
Ynne il 4 Gen 2018
Risposto: Samay Sagar il 24 Set 2024
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 Commento
Adriana Royuela
Adriana Royuela il 13 Feb 2024
Hi! I have the same problem. How did you end up doing it?

Accedi per commentare.

Risposte (1)

Samay Sagar
Samay Sagar il 24 Set 2024
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:

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by