Use Image Segmenter on *.fig figures

2 ビュー (過去 30 日間)
AM_JC
AM_JC 2021 年 2 月 4 日
回答済み: Vidhi Agarwal 2024 年 4 月 24 日
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 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 2 月 5 日
Is there any problem to segment the image using code and display it later?
AM_JC
AM_JC 2021 年 2 月 5 日
I am not sure I understand what you mean.
You suggest I segment the .png image using imfreehand function rather than the Image Segmenter ?
But the issue will remain as I won't have the coordinates of the data points I want to extract from the *.fig file.

サインインしてコメントする。

回答 (1 件)

Vidhi Agarwal
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:
  1. Extract Data from .fig Files
  2. Use Image Processing Directly on Data
  3. 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:

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by