Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

1GB MPH file resulting from importing a 4KB Image via MPHIMAGE2GEOM... Why?!

Please login with a confirmed email address before reporting spam

We are trying to import the attached small image into COMSOL using the mphimage2geom command in Matlab Livelink (relevant piece of code is below for your reference). The resulting mph file is over 1GB large, and takes forever to write. What is the cause of the huge file size, and how to avoid this?

COMSOL techsupport recommended importing the image using Functions>Image, and then "it will behave like a function". So does this mean that MPHIMAGE2GEOM is useless? Or am I using it in the wrong way somehow? Please explain...

Thanks.
-------------------------------------CODE BELOW-------------------------------------------------------
L = bwlabel(bw_image);

total_objects_number = max(unique(L)); %get the number of cells

for this_object_number = 1:total_objects_number

this_bw_object = L == this_object_number; %select THIS cell from GROUP of cells

%% obtain COMSOL geometry from image

img_geometry_MODEL_tag = ['Cell_' num2str(this_object_number)];

image_2_geom = mphimage2geom(this_bw_object,1,'Modeltag',img_geometry_MODEL_tag);

%INSERT this cell's COMSOL Geometry into the COMSOL model
model.geom('geom1').insertSequence(img_geometry_MODEL_tag,'geom1');

end

model.geom('geom1').run;


1 Reply Last Post 02.05.2016, 06:32 GMT-4
Lars Gregersen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 02.05.2016, 06:32 GMT-4
Hi Roman

I'm not entirely sure what you are aiming for and what you wish to use the imported data for so here is an explanation:

mpimage2geom is a function that convert an image into a Comsol geometry. This Comsol geometry will have domains and boundaries that you later can use for setting up your physics. This works well when you really need to include sharp changes between different domains in your model. The size of geometry data will depend on your image, but should normally not result in a model of 1 GB.
If you don't need great accuracy you can work with image data as a function and e.g. use the function for setting up material data or sources in your model. This is useful for numerous applications and it depends very much on the physics whether or not this approach makes sense.

In your case a single call to mphimage2geom will do:
model=mphimage2geom(im,1,'rect','on')

This will create a new model that you can later add physics and solver settings to.

If you instead wish to add the newly created geometry to an existing model (that has a geometry with the tag 'geom1') you can do:
mphimage2geom(im,1,'rect','on','geom',model.geom('geom1'))


Remember you can always save your model (using mphsave) as an MPH-file and load it into Comsol Multiphysics to see exactly what curve data your image has been converted into.

Let me know if this works for you.

--
Lars Gregersen
Comsol Denmark
Hi Roman I'm not entirely sure what you are aiming for and what you wish to use the imported data for so here is an explanation: mpimage2geom is a function that convert an image into a Comsol geometry. This Comsol geometry will have domains and boundaries that you later can use for setting up your physics. This works well when you really need to include sharp changes between different domains in your model. The size of geometry data will depend on your image, but should normally not result in a model of 1 GB. If you don't need great accuracy you can work with image data as a function and e.g. use the function for setting up material data or sources in your model. This is useful for numerous applications and it depends very much on the physics whether or not this approach makes sense. In your case a single call to mphimage2geom will do: model=mphimage2geom(im,1,'rect','on') This will create a new model that you can later add physics and solver settings to. If you instead wish to add the newly created geometry to an existing model (that has a geometry with the tag 'geom1') you can do: mphimage2geom(im,1,'rect','on','geom',model.geom('geom1')) Remember you can always save your model (using mphsave) as an MPH-file and load it into Comsol Multiphysics to see exactly what curve data your image has been converted into. Let me know if this works for you. -- Lars Gregersen Comsol Denmark

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.