Use Image Segmenter on *.fig figures
2 次查看(过去 30 天)
显示 更早的评论
Hello all,
I have pictures that I plot using Matlab and are hence in .fig format. Data are comprised between -1 and 1 and I want to use the Image Segmenter directly on these figures and extract the values of the segmented region to do further calculations.
However the Matlab Image Segmenter (imfreehand function and co) does not recognize *.fig files. I thus have to print my figures in png files for instance and do the segmentation on these pictures.
The issues are that I am losing information with the png image since the values are then coded in grayscale (255 levels) and I cannot use the generated mask to extract data from the fig files since the frame is not the same; I start with a 512X640 image (.fig) and end up with a random 656X875 image(png) because of the white frame among other things.
Does anyone know how to do this ? Maybe imfreehand is not best suited for this.
Thanks
2 个评论
回答(1 个)
Vidhi Agarwal
2024-4-24
Hi,
I understand you are facing the issue of loss of information while storing your figures in ‘.png’.
To solve this issue, you can use techniques that engage directly with the data housed within ‘.fig’ files or ensure that converting ‘.fig’ files into an image format like `.png’ preserves all vital information. Since ‘.fig’ files are MATLAB figures saved in a format that includes all the figure properties and data, you can extract the data directly from the ‘.fig’ file without converting it to an image file. In this way, it is easy to maintain the original data's integrity and avoid the issues related to image resolution and grayscale conversion.
The following approach can help you get started:
- Extract Data from ‘.fig’ Files
- Use Image Processing Directly on Data
- Matching Coordinates and Resolution
Here is a sample code illustrating this approach:
fig = openfig('myFigure.fig', 'invisible');
ax = findobj(fig, 'Type', 'axes');
h = findobj(ax, 'Type', 'image');
imageData = get(h, 'CData');
imshow(imageData, []);
hFreehand = drawfreehand('Color','r');
binaryMask = createMask(hFreehand);
% Convert binaryMask to the same class as imageData
binaryMaskConverted = cast(binaryMask, class(imageData));
% Now perform the element-wise multiplication
segmentedData = imageData .* binaryMaskConverted;
f = figure;
ax = axes('Parent', f);
imagesc(ax, segmentedData); % Display segmentedData instead of imageData
axis(ax, 'image');
print(f, 'output_image.png', '-dpng', '-r300');
For further detailed information about “figures”, “cast” and “drawfreehand” you can refer to this documentation:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!