New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color. Obj file #2
Comments
Hi christian, from the information you gave it sounds like you are applying uv coordinates and a texture file. Is that correct? While I think that would be a more elegant solution in line with .obj best practices that is not how the current version of the function is built. Does this answer your question? If you want to use this function, I think it should be relatively straightforward to pull out the list (Nx3 matrix) of RGB values from the colormap file you seem to have using uv coordinates. If you still run into issues (or if I misunderstood the question) please provide some example code and data. Benjamin |
** Reply Requested When Convenient **
Hy!
It time for me to introduce myselfe to you I'm working for University
of Linz,
Johannes Kepler Universität Austria. I'm working on a project ( i try
to cannot get all the resources from university witch is in a half
corona lock down)
I try to visualisze US Data visualize to HMD and CAVE.
my code:
A = imread ('Bild_100.png');
%(A 512x512)
colormap jet;
fvc=surf2patch(X,Y,A,A)
%result
% fvc.faces fvc.vertices fvc,facesvertexcdata
obj_write_color(fvc, 'demo', c);
lenght matches n vertices -> using vertex color median as face mtl
definition
Error using .*
Integers can only be combined with integers of the same class, or
scalar doubles.
Error in linspace (line 44)
y = d1 + (0:n1).*(d2 - d1)./n1;
Error in obj_write_color (line 130)
cbin_edges=linspace(cmin, cmax, RGB_bins+1);
Sorry i dont know why getting this error
mfg
christian
>> "J. Benjamin Kacerovsky" ***@***.***> 12.02.2021
22:22 >>>
Hi christian, from the information you gave it sounds like you are
applying uv coordinates and a texture file. Is that correct? While I
think that would be a more elegant solution in line with .obj best
practices that is not how the current version of the function is built.
I tried to make the script similar in terms of input and usage to the
built in patch function. So the color input requires either a vector of
a continuous variable, Nx1 matrix and a colormap (one of the built in
Matlab colormaps) or a list of RGB values, Nx3 matrix, where N should be
equal to the number of faces or vertices of the mesh object. Each unique
colour is saved as a different material. I know this is not super
efficient, since it can lead to a potentially very large number of
materials on the same object (and it doesn't really allow for smooth
colours), but this was most straightforward to implement as a direct
adaptation from the patch function, which I was using in Matlab before.
Does this answer your question? If you want to use this function, I
think it should be relatively straightforward to pull out the list (Nx3
matrix) of RGB values from the colormap file you seem to have using uv
coordinates. If you still run into issues (or if I misunderstood the
question) please provide some example code and data.
Benjamin
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
(
#2 (comment))
, or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/ASEMQWREBSOVCURVZNI6ZX3S6WLZFANCNFSM4XRD25WA)
.
|
Hi Christian, Oh cool, ich komm' auch aus Österreich :) I studied in Vienna. I took a look at your example. The error you are getting seems to be because different numeric types are passed to linspace. fvc.facevertexcdata from surf2patch on an 8-bit png is of numeric type uint8, but the other variables passed to linspace in line 130 are of type double, so it throws an error. You can simply convert your color vector to double and it should fix the issue. I also added a quick fix into the code (simple enforcing types double for the relevant variables) so if you pull the repo it should be fixed and you should be able to run the obj_write_color.m function without having to convert anything. Please note that the function is written specifically for triangle meshes, so you will have to specify 'triangles' for surf2patch (see code example below). If you pass quad-meshes in, some bizarre shapes emerge :p below you have a code example (using one of the .png images that come with the Matlab distribution I believe) that shows the fix with the 'old' and new versions of the function: `A=imread('peppers.png'); Z=rescale(mean(A, 3), 0, 90); %% Z scale as averagee rgb values fvc=surf2patch(X,Y,Z,B, 'triangles'); % test with matlabb figure %% export colour obj file %% with updated version (feb-15) of obj_write_color.m %% testing accessing the rgb values for each pixel directly from source file and mapping to mesh/.obj file r = A(:, :, 1); rgb = [r, g, b]; rgb = double(rgb)/255; obj_write_color((fvc), 'demo_rgb', rgb, 'illum', 5); |
** Reply Requested When Convenient **
Hi !
So you studiet in Vienna , as Austria is not very big :-) this is only
150 km from me.
Kommst du aus Österreich oder hat du nur in Österreich studiert.
Some realy nice Projekts about Science Computing (VSC) are going on
there. The Data from the US Simulation were made with VSC Vienna.
THANK YOU for you help ,i try it right away in a few moments. Now i
dont write to you on the Handy becouse as you saw the writing mistakes
my handy always translates the word into german to some really strange
words and i didnt notice that.
I give you some results as soon as i finish working OK
Thank you.
mfg
Christian
-- Johannes Kepler Universitaet
-- Christian Wohlschlager
-- Altenbergerstr.69
-- 4040 Linz Austria
-- Tel: +43 732 2468 3897
- Mail:christian.wohlschlager@jku.at
>> "J. Benjamin Kacerovsky" ***@***.***> 15.02.2021
22:59 >>>
Hi Christian,
Oh cool, ich komm' auch aus Österreich :) I studied in Vienna.
I took a look at your example. The error you are getting seems to be
because different numeric types are passed to linspace.
fvc.facevertexcdata from surf2patch on an 8-bit png is of numeric type
uint8, but the other variables passed to linspace in line 130 are of
type double, so it throws an error.
You can simply convert your color vector to double and it should fix
the issue. I also added a quick fix into the code (simple enforcing
types double for the relevant variables) so if you pull the repo it
should be fixed and you should be able to run the obj_write_color.m
function without having to convert anything.
Please note that the function is written specifically for triangle
meshes, so you will have to specify 'triangles' for surf2patch (see code
example below). If you pass quad-meshes in, some bizarre shapes emerge
:p
below you have a code example (using one of the .png images that come
with the Matlab distribution I believe) that shows the fix with the
'old' and new versions of the function:
`A=imread('peppers.png');
B=A(:, :, 1);
[X, Y] = meshgrid(1:512, 1:384); %% X, Y as pixel coordinates
Z=rescale(mean(A, 3), 0, 90); %% Z scale as averagee rgb values
fvc=surf2patch(X,Y,Z,B, 'triangles');
% test with matlabb figure
figure
patch(fvc, 'edgecolor', 'none', 'facevertexcdata',
double(fvc.facevertexcdata), 'facecolor', 'flat');
colormap jet
axis equal
%% export colour obj file
% this fixes the issue of the previous iteration of the function
% the numeric typee of 'colors' gets passed to cmin and cmax. The
linspace
% function requires all input variables to be of the same type, in
this
% case double.
obj_write_color((fvc), 'demo', double(fvc.facevertexcdata), 'colorMap',
'jet', 'illum', 10);
%% with updated version (feb-15) of obj_write_color.m
% the most recent update of obj_write_color.m converts cmin and cmax
to
% double, so it should also work without issue if the numeric type of
% colors is 'uint8', as is the case in the above example.
obj_write_color((fvc), 'demo_double', (fvc.facevertexcdata),
'colorMap', 'jet', 'illum', 10);
%% testing accessing the rgb values for each pixel directly from source
file and mapping to mesh/.obj file
yy = fvc.vertices(:, 1);
xx = fvc.vertices(:, 2);
r = A(:, :, 1);
r = r(sub2ind(size(r), xx, yy));
g = A(:, :, 2);
g = g(sub2ind(size(g), xx, yy));
b = A(:, :, 3);
b = b(sub2ind(size(b), xx, yy));
rgb = [r, g, b];
rgb = double(rgb)/255;
obj_write_color((fvc), 'demo_rgb', rgb, 'illum', 5);
`
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
(
#2 (comment))
, or unsubscribe
(
https://github.com/notifications/unsubscribe-auth/ASEMQWU3BGOBYMQTA262X73S7GKLBANCNFSM4XRD25WA)
.
|
** Reply Requested When Convenient **
Hier
Ja ja ja working now first coding succesful ltell you later when full
progress ist Doberan
MFG
Christian
>> "J. Benjamin Kacerovsky" ***@***.***> 15.02.21 22.59
Uhr >>>Hi Christian,
Oh cool, ich komm' auch aus Österreich :) I studied in Vienna.
I took a look at your example. The error you are getting seems to be
because different numeric types are passed to linspace.
fvc.facevertexcdata from surf2patch on an 8-bit png is of numeric type
uint8, but the other variables passed to linspace in line 130 are of
type double, so it throws an error.
You can simply convert your color vector to double and it should fix the
issue. I also added a quick fix into the code (simple enforcing types
double for the relevant variables) so if you pull the repo it should be
fixed and you should be able to run the obj_write_color.m function
without having to convert anything.
Please note that the function is written specifically for triangle
meshes, so you will have to specify 'triangles' for surf2patch (see code
example below). If you pass quad-meshes in, some bizarre shapes emerge
:p
below you have a code example (using one of the .png images that come
with the Matlab distribution I believe) that shows the fix with the
'old' and new versions of the function:
`A=imread('peppers.png');
B=A(:, :, 1);
[X, Y] = meshgrid(1:512, 1:384); %% X, Y as pixel coordinates
Z=rescale(mean(A, 3), 0, 90); %% Z scale as averagee rgb values
fvc=surf2patch(X,Y,Z,B, 'triangles');
% test with matlabb figure
figure
patch(fvc, 'edgecolor', 'none', 'facevertexcdata',
double(fvc.facevertexcdata), 'facecolor', 'flat');
colormap jet
axis equal
%% export colour obj file
% this fixes the issue of the previous iteration of the function
% the numeric typee of 'colors' gets passed to cmin and cmax. The
linspace
% function requires all input variables to be of the same type, in this
% case double.
obj_write_color((fvc), 'demo', double(fvc.facevertexcdata), 'colorMap',
'jet', 'illum', 10);
%% with updated version (feb-15) of obj_write_color.m
% the most recent update of obj_write_color.m converts cmin and cmax to
% double, so it should also work without issue if the numeric type of
% colors is 'uint8', as is the case in the above example.
obj_write_color((fvc), 'demo_double', (fvc.facevertexcdata), 'colorMap',
'jet', 'illum', 10);
%% testing accessing the rgb values for each pixel directly from source
file and mapping to mesh/.obj file
yy = fvc.vertices(:, 1);
xx = fvc.vertices(:, 2);
r = A(:, :, 1);
r = r(sub2ind(size(r), xx, yy));
g = A(:, :, 2);
g = g(sub2ind(size(g), xx, yy));
b = A(:, :, 3);
b = b(sub2ind(size(b), xx, yy));
rgb = [r, g, b];
rgb = double(rgb)/255;
obj_write_color((fvc), 'demo_rgb', rgb, 'illum', 5);
`
…--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#2 (comment)
|
Thank you for the quick andere Titel my
Demo_obj question!!!!!!!!
I have 512x512x3 RGB values for my surface but when in put it to write_obj_color
I get an error. ( if you need more info I send you the source
Thank you
Christian
The text was updated successfully, but these errors were encountered: