필터 지우기
필터 지우기

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 CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by