Use Image Segmenter on *.fig figures

2 visualizaciones (últimos 30 días)
AM_JC
AM_JC el 4 de Feb. de 2021
Respondida: Vidhi Agarwal el 24 de Abr. de 2024
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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 5 de Feb. de 2021
Is there any problem to segment the image using code and display it later?
AM_JC
AM_JC el 5 de Feb. de 2021
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.

Iniciar sesión para comentar.

Respuestas (1)

Vidhi Agarwal
Vidhi Agarwal el 24 de Abr. de 2024
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:

Categorías

Más información sobre Images en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by