Export groundTruth as single png image
조회 수: 9 (최근 30일)
이전 댓글 표시
I would like to export my labels generated using imageLabeler any of the following:
- a png RGB image
- a 2D matrix of ImageHeightxImageWidth with the class number at each position i, j
- or the same matrix but in 3D as the one-hot-encoded version.
- If not possible, at least one image per class of any of the previous ones.
Having the vertices of each polygon is not useful for me obviously. Basically I need something I can then feed into a u-net network for semantic segmentation.
Possible outcomes:
- I saw a partial solution [here](https://fr.mathworks.com/matlabcentral/answers/381245-how-to-extract-images-from-groundtruth-object#answer_411774) but it's for rectangle labels and mines are polygons.
- According to this there is a folder called PixelLabelData which has what I need, only that I can't find it.
- I tried exporting gTruth to the workspace and then I tried `pxds = pixelLabelDatastore(gTruth)` as suggested here but I have the error `The value of 'gTruth' is invalid. groundTruth objects must contain a label definition table with PixelLabel type.`. According to this is something about the paths but the png paths are Ok, I moved nothing. The message seems to be the LabelDefinition Type parameter which is indeed weird. It's just a '7' as shown in the attached figure.
- Using `[imds,pxds] = pixelLabelTrainingData(gTruth)` as suggested [here](https://fr.mathworks.com/help/vision/ref/pixellabeltrainingdata.html) has the error message of [this](https://fr.mathworks.com/matlabcentral/answers/1616790-no-pixel-label-data-found-using-the-pixellabeltrainingdata-function) question.
I can try to implement the code myself but it seems like a lot of work and something that should already be implemented somewhere, looks to me like a quite normal application. How is this done?
I am really getting mad at this... This should have been a button inside the export options... Instead I am loosing a lot of time with a simple thing. I will eventually find the solution and post it here.
댓글 수: 0
채택된 답변
Birju Patel
2022년 5월 5일
As you noticed, you will have to use pixel labels instead of polygons to get to a label matrix directly from the image or video labeler apps. The label matrix is saved in a PNG file when the label type is pixel label.
However, if you have polygon labels, you can use POLY2LABEL to convert them to label matrices that can be saved as PNG files using IMWRITE:
댓글 수: 0
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!