You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Vectorization] Step 5 of Centerline Vectorization #849
Now I would Like to add @blackwarthog@ice0 in the discussion that in the image below I am at the highlighted step
As you can see that further steps involve stroke and color palette which are not present in synfig
So I am thinking to store the RGBA value for single sequence and then use that for that sequence in the skeleton
@morevnaproject
openToonz use PixelCM32 (a 32-bit color map 12+12+8 bits (ink,paint,tone)) to represent the pixel and the function int getTone() const { return m_value & 0xFF; };
is used to compare with the threshold while taking color samples in function - > samplecolor (...)
So what should I use to replace threshold comparison?
and it stores an int value as m_color in the sequence which is given by int getInk() const { return m_value >> 20; };
So I am thinking to store the RGBA value for single sequence and then use that for that sequence in the skeleton
as per my comment I think replacing int m_color with synfig::Color::m_color will do the work
openToonz use PixelCM32 (a 32-bit color map 12+12+8 bits (ink,paint,tone)) to represent the pixel
@ankit-kumar-dwivedi Sorry, I do not understand what (ink,paint,tone) model means. In particular, I do not understand what the difference of ink from paint. ^__^"
@ankit-kumar-dwivedi Sorry, I do not understand what (ink,paint,tone) model means. In particular, I do not understand what the difference of ink from paint. ^__^"
Actually, I was not able to find where the RGB to C-map conversion is taking place so I thought you might be already knowing it (・_・ヾ
I am trying to find more about it. Currently looking at the code responsible for loading raster images in Opentoonz
@ankit-kumar-dwivedi It looks I figured out what PixelCM32 means. This seems to be pixels from "Toonz Raster Level" (it is not the same as ordinary "Raster Level").
As you can see, in Toonz Raster Level one image actually contains two "layers" - one for "ink" (lines) and one for "paint" (fills). So, each pixel has information for two colors - color of "ink" and color of "paint". There is also a third component - "tone", which represents transparency of this part of image (applied after "ink" mixed with "paint").
More than that, values of "ink" and "paint" are not really colors - (my guess) they are numbers, referencing colors from palette (by index).
32-bit color map 12+12+8 bits (ink,paint,tone)
So, first 12 bytes reference color number for "ink" from palette.
Next 12 bytes reference color index for "paint".
Last 8 bytes is a transparency value.
I hope that helps. ^__^
Not sure why this function uses "Toonz Raster Level" (PixelCM32) instead of ordinary "Raster Level".
As you can see, in Toonz Raster Level one image actually contains two "layers" - one for "ink" (lines) and one for "paint" (fills). So, each pixel has information for two colors - color of "ink" and color of "paint". There is also a third component - "tone", which represents transparency of this part of image (applied after "ink" mixed with "paint").
But then the imported image has no such property so how do they get converted?
More than that, values of "ink" and "paint" are not really colors - (my guess) they are numbers, referencing colors from palette (by index).
I think so as the function definition says:
Take samples of image colors to associate each sequence to its corresponding palette color. Currently working on colormaps.
And this again leaves me with the question what should I comapre with the threshold. I think I should use the same as I used in polygonizer the luminance model.
So now I am going to use it. But from now onwards we will not be able to compare the results with toonz as we will be using outline layer in place of stroke
That is because they converted it to Toonzraster level see 373 and 378
so how do they get converted?
It worth to look how conversion from regular bitmap to TRasterCM32P is actually done. Probably this is done via assignment operator, which is possibly defined in TRasterCM32P class.
@morevnaproject actually there is no assignment operator defined
Let us see what is happening here TRasterP &ras is passed to the function void calculateSequenceColors(....)
and then inside the function we see TRasterCM32P cm = ras Now have a look at the image below
here ⬇️ implies inheritance and all classes except TRaster are template classes
Here is something interesting I found in pixelevaluator (inside polygonizer)
If the T in TRasterPT
if T = TPixelCM32 getBlackOrWhite(int x, int y) { return m_ras->pixels(y)[x].getTone() < m_threshold; }
if T = TPixel32 getBlackOrWhite(int x, int y) { return std::max(m_ras->pixels(y)[x].r, std::max(m_ras->pixels(y)[x].g, m_ras->pixels(y)[x].b)) < m_threshold * (m_ras->pixels(y)[x].m / 255.0); }
So @morevnaproject I think it will be okay if I replace the tone() and threshold comaprison with the above method
Also is there a better way to access the pixels?
currently, this is how I access the pixel data row and column (x,y) from ras
```
synfig::rendering::SurfaceResource::LockRead<synfig::rendering::SurfaceSW> lock( m_ras->rendering_surface );
const Surface &surface = lock->get_surface();
const int Y = surface.get_h() - y -1;
const Color *row = surface[Y];
int r = 255.0*pow(row[x].get_r(),1/2.2);
int g = 255.0*pow(row[x].get_g(),1/2.2);
int b = 255.0*pow(row[x].get_b(),1/2.2);
int a = 255.0*pow(row[x].get_a(),1/2.2);
```
it's a proper way to access the pixels
I am talking about const int Y = surface.get_h() - y -1
synfig stores image rows from top to bottom
so, by this logic you will read image from bottom to top
is it right for you?
in synfig you may use Vector3::nan() or Point3::nan() (Point3 if typedef of Vector3) for 3D
Thanks :)
synfig stores image rows from top to bottom so, by this logic you will read an image from bottom to top is it right for you?
Actually, this was how I fixed the image roation see -> #735 (comment)
For a given value of (int x, int y) to get the respective RGBA values
Earlier I was using
synfig::rendering::SurfaceResource::LockRead<synfig::rendering::SurfaceSW> lock( m_ras->rendering_surface );
const Surface &surface = lock->get_surface();
const Color *row = surface[x];
int r = 255.0*pow(row[y].get_r(),1/2.2);
int g = 255.0*pow(row[y].get_g(),1/2.2);
int b = 255.0*pow(row[y].get_b(),1/2.2);
int a = 255.0*pow(row[y].get_a(),1/2.2);
and changing it to
synfig::rendering::SurfaceResource::LockRead<synfig::rendering::SurfaceSW> lock( m_ras->rendering_surface );
const Surface &surface = lock->get_surface();
const int Y = surface.get_h() - y -1;
const Color *row = surface[Y];
int r = 255.0*pow(row[x].get_r(),1/2.2);
int g = 255.0*pow(row[x].get_g(),1/2.2);
int b = 255.0*pow(row[x].get_b(),1/2.2);
int a = 255.0*pow(row[x].get_a(),1/2.2);
So, if we pass regular raster image to calculateSequenceColors(....) then content of function is just doesn't invoked at all, as the pointer check returns false. ^__^
So, if we pass regular raster image to calculateSequenceColors(....) then content of function is just doesn't invoked at all, as the pointer check returns false. ^__^
@morevnaproject does this implies that I don't need to recreate this at all? o:-)
Activity
ankit-kumar-dwivedi commentedon Jun 21, 2019
Now I would Like to add @blackwarthog @ice0 in the discussion that in the image below I am at the highlighted step

As you can see that further steps involve stroke and color palette which are not present in synfig
So I am thinking to store the RGBA value for single sequence and then use that for that sequence in the skeleton
and as per @morevnaproject
[-]Step 5 of Centerline Vectorization [/-][+][Vectorization] Step 5 of Centerline Vectorization [/+]ankit-kumar-dwivedi commentedon Jun 24, 2019
@morevnaproject
openToonz use PixelCM32 (a 32-bit color map 12+12+8 bits (ink,paint,tone)) to represent the pixel and the function
int getTone() const { return m_value & 0xFF; };is used to compare with the threshold while taking color samples in function - > samplecolor (...)
So what should I use to replace threshold comparison?
and it stores an int value as m_color in the sequence which is given by
int getInk() const { return m_value >> 20; };as per my comment I think replacing
int m_colorwithsynfig::Color::m_colorwill do the workmorevnaproject commentedon Jun 26, 2019
@ankit-kumar-dwivedi Sorry, I do not understand what (ink,paint,tone) model means. In particular, I do not understand what the difference of ink from paint. ^__^"
Logically "Tone" = "Hue" in HSV color model (https://en.wikipedia.org/wiki/Hue). But my intuition tells me that "Tone" means "Value" (from HSV) here. Is it so?
In any case,
Synfig::Colorobject hasget_hue()function to get Hue(https://github.com/synfig/synfig/blob/master/synfig-core/src/synfig/color/color.h#L183).If you need "Value" of HSV, then it requires converting to HSV - https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
@blackwarthog your thoughts on this?
ankit-kumar-dwivedi commentedon Jun 26, 2019
Actually, I was not able to find where the RGB to C-map conversion is taking place so I thought you might be already knowing it (・_・ヾ
I am trying to find more about it. Currently looking at the code responsible for loading raster images in Opentoonz
Added sampleColor function
morevnaproject commentedon Jun 27, 2019
@ankit-kumar-dwivedi It looks I figured out what PixelCM32 means. This seems to be pixels from "Toonz Raster Level" (it is not the same as ordinary "Raster Level").
The explanation on how Toonz Raster Level works can be found here - https://morevnaproject.org/2017/03/17/toonz-raster-level/
As you can see, in Toonz Raster Level one image actually contains two "layers" - one for "ink" (lines) and one for "paint" (fills). So, each pixel has information for two colors - color of "ink" and color of "paint". There is also a third component - "tone", which represents transparency of this part of image (applied after "ink" mixed with "paint").
More than that, values of "ink" and "paint" are not really colors - (my guess) they are numbers, referencing colors from palette (by index).
So, first 12 bytes reference color number for "ink" from palette.
Next 12 bytes reference color index for "paint".
Last 8 bytes is a transparency value.
I hope that helps. ^__^
Not sure why this function uses "Toonz Raster Level" (PixelCM32) instead of ordinary "Raster Level".
ankit-kumar-dwivedi commentedon Jun 27, 2019
@morevnaproject That is because they converted it to Toonzraster level see 373 and 378
https://github.com/morevnaproject/opentoonz/blob/ac3067fb0cdbdcbc4f7fca959cf0d6c212586fb4/toonz/sources/toonzlib/tcenterlinecolors.cpp#L373-L378
But then the imported image has no such property so how do they get converted?
I think so as the function definition says:
And this again leaves me with the question what should I comapre with the threshold. I think I should use the same as I used in polygonizer the luminance model.
So now I am going to use it. But from now onwards we will not be able to compare the results with toonz as we will be using outline layer in place of stroke
morevnaproject commentedon Jun 28, 2019
It worth to look how conversion from regular bitmap to TRasterCM32P is actually done. Probably this is done via assignment operator, which is possibly defined in TRasterCM32P class.
ankit-kumar-dwivedi commentedon Jun 28, 2019
@morevnaproject actually there is no assignment operator defined
Let us see what is happening here
TRasterP &rasis passed to the function void calculateSequenceColors(....)and then inside the function we see
TRasterCM32P cm = rasNow have a look at the image below
here ⬇️ implies inheritance and all classes except TRaster are template classes
ankit-kumar-dwivedi commentedon Jun 28, 2019
These classes are defined in traster.h just in case if I overlooked any of them
And the typedef for TRasterCM32P
ankit-kumar-dwivedi commentedon Jun 28, 2019
Here is something interesting I found in pixelevaluator (inside polygonizer)
If the T in TRasterPT
getBlackOrWhite(int x, int y) { return m_ras->pixels(y)[x].getTone() < m_threshold; }getBlackOrWhite(int x, int y) { return std::max(m_ras->pixels(y)[x].r, std::max(m_ras->pixels(y)[x].g, m_ras->pixels(y)[x].b)) < m_threshold * (m_ras->pixels(y)[x].m / 255.0); }So @morevnaproject I think it will be okay if I replace the tone() and threshold comaprison with the above method
4 remaining items
blackwarthog commentedon Jun 30, 2019
ankit-kumar-dwivedi commentedon Jun 30, 2019
@blackwarthog
EDIT: Okay I found it here
Thanks :)
Actually, this was how I fixed the image roation see -> #735 (comment)
For a given value of (int x, int y) to get the respective RGBA values
fixed the error.
Centerlinecolors.cpp completed (Compiled Successfuly)
ankit-kumar-dwivedi commentedon Jun 30, 2019
Closing after ankit-kumar-dwivedi@7734ac9
morevnaproject commentedon Jul 1, 2019
Just some clarifications on #849 (comment):
Actually, there are no conversion happens in
calculateSequenceColors(....). See below....and just a little below at line 378 there is a check if
cmis valid pointer:You might see a similar check in
centerlineVectorize()function here:https://github.com/morevnaproject/opentoonz/blob/ac3067fb0cdbdcbc4f7fca959cf0d6c212586fb4/toonz/sources/toonzlib/tcenterlinevectorizer.cpp#L173
So, if we pass regular raster image to
calculateSequenceColors(....)then content of function is just doesn't invoked at all, as the pointer check returns false. ^__^morevnaproject commentedon Jul 1, 2019
Congratulations! ^__^
ankit-kumar-dwivedi commentedon Jul 1, 2019
@morevnaproject does this implies that I don't need to recreate this at all? o:-)
morevnaproject commentedon Jul 3, 2019
You need this only if you are going to detect and apply colors to strokes. ^__^
Added sampleColor function
Centerlinecolors.cpp completed (Compiled Successfuly)
Added sampleColor function
Centerlinecolors.cpp completed (Compiled Successfuly)
Added sampleColor function
Centerlinecolors.cpp completed (Compiled Successfuly)