I want to calculate the coverage of cmyk color + the coverage of white.
I only have no clue of how to calculate the white.
if c, m, y, and k go from 0 to 1 is then white:
w = 1 - (c+m+y+k/4)
or is it:
w = 1- c-m-y-k
(and the clamped to be 0 or above so it's not minus something)
Or is it more complex then that?
In one "standard definition" of CMYK, converting from RGB goes like this:
K=min(R,G,B)
C=(1-R-K)/(1-K)
M=(1-G-K)/(1-K)
Y=(1-B-K)/(1-K)
I think the level of white in a color would just be W=1-K, but I'm not entirely sure if that's what you're asking...
Related
I am using Path Construction in PDF to draw a shape, say a rectangle. For example:
0 0 m 0 1 l 1 1 l 1 0 l 0 0 l B
But now, the line connecting (0,0) and (0,1) has (0,0) and (0,1) in the center. Therefore, the boundary "leaves" the rectangle by half of the line width.
Is there a parameter, so that the boundary is drawn entirely inside the rectangle?
This is just the normal behaviour of the line drawing operation.
The thickness of the line is spread equally to both sides of the line. So if you have a 10pt think line from (0,0) to (10,0) and use the butt cap line style, you will have a filled rectangular area with the corners (0,-5), (10,-5), (10,5), (0,5).
Have a look at this PDF file - you can see this effect in the second row, second column. The inner white lines and the outer black lines have the same start and end points.
So if you want to have everything inside that rectangle, either using a clip path like mkl said or calculate the necessary end points, taking the line width and line cap/join style into account.
As already mentioned in a comment, using a clip path the size of that rectangle is an option.
As your path only consists of the rectangle in question, you can do so very easily, simply add the clipping path operator W before the path painting operator B:
0 0 m 0 1 l 1 1 l 1 0 l 0 0 l W B
If you don't want to keep the clip path, enclose all this in save-state/restore-state
q
0 0 m 0 1 l 1 1 l 1 0 l 0 0 l W B
Q
How can I find or generate data points form a shape in 2D in MATLAB ? For example, the letters A, B, and C.
You can use fill()
An example for an octogon, provided by
See https://www.mathworks.com/help/matlab/ref/fill.html
% Generate the points required for the fill.
t = (1/16:1/8:1)'*2*pi; % using 1/8 steps we get an 8 sided object.
x = cos(t);
y = sin(t);
% fill the data
fill(x,y,'r')
axis square % prevent skewing the result.
An example of generating the x y coordinates of a rectangle with an offset of (5,5):
x=[5 5 25 25 5]
y=[5 15 15 5 5]
You have 5 points because you need to include the final point to complete the path ( I believe ) Follow the blue path when collecting the x coordinates and the y coordinates. You can see we start at 5,5 then move to 5,15 --- so the first part of the path is
x=[5 5 ...
y=[5 15 ...
If you want to generate the coordinates automatically, you could use a program like InkScape (vector program) to help you convert a character to paths, but here is a simple example drawn with the pen tool:
The points are given by
m 0,1052.3622 5,-10 5,0 5,10 z
which 1052.3622 is VERY large, but is ultimately because I placed my shape at the bottom of the page. if we set this to be 0,0 it would go to the top of the page.
def mysterious(pic):
w =getWidth(pic)
h = getHeight(pic)
for y in range(1, h+1):
for x in range(1, w/2+1):
p1 = getPixel(pic, x, y)
p2 = getPixel(pic, w-x+1, h-y+1)
c1 = getColor(p1)
setColor(p1, getColor(p2))
setColor(p2, c1)
It looks like the picture's color is getting inverted from one end to another.
The pixel color at the end of the picture is being inserted at the beginning of the picture and vice versa.
The code also depends on the height and width of the picture. It controls the for loop, so depending on that, the amount of pixels will change color
A friend gave me a logo which he created in Adobe Illustrator CS 5 with a rectangle in blue color (Cyan 100%, M 0%, Y 0%, B 0%) and saved it as PDF. I opened the PDF-file in Adobe Illustrator CS 6 17.0.0.
When I used the pipette to get the color information the result was: Cyan 74%, Magenta 24%, Y 0%, B 0%.
I tried to put two other rectangles over it. One with the original color: Cyan 100%, M 0%, Y 0%, B 0%
And one with the measured color: Cyan 74%, Magenta 24%, Y 0%, B 0%
The one with the original color looks 100% same like the logo. (different values...)
And the one with the measured color looks different. (same values...)
Any idea? Is it a bug?
Adobes pipette reads only the RGB values and calculates the CMYK values even if the document is in CMYK - Mode.
If you make a small calculation than you can see that CMYK can hold about 10^8 numbers (100 C; * 100 M; * 100 Y; * 100 K;) while RGB can only hold 16,7 * 10^6 (R 256; * G 256; * B 256) which gives a gab of 83*10^6 values. So there is more than one value in CMYK that gives the same RGB value as another CMYK value.
I'm overplotting multicolored lines on an image, the color of the lines is supposed to represent a given parameter that varies between roughtly -1 and 3.
The following portion of code is the one that builds these lines :
x = self._tprun.r[0,p,::100] # x coordinate
y = self._tprun.r[1,p,::100] # y coordinate
points = np.array([x, y]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
# 'color' is the parameter that will color the line
vmin = self._color[p,:].min()
vmax = self._color[p,:].max()
lc = LineCollection(segments,
cmap=plt.get_cmap('jet'),
norm=plt.Normalize(vmin=vmin,vmax=vmax))
lc.set_array(self._color[p,:])
lc.set_linewidth(1)
self._ax.add_collection(lc)
This code is inside a loop on 'p' and so it will create several lines at locations given by the arrays 'x' and 'y' and for which the color should be given by the value of 'self._color[p,:]'.
As I said, '_color[p,:]' roughly varies between -1 and 3. Here is an example of what '_color[p,:]' may be :
My problem is that the lines that are created appear without much variation of the color, they all look kind of monochrome dark blue whereas _color[p,:] varies much and I ask for the normalization to take its min/max values.
here is an example of such a line (look at the oscillating dark blue line, other black lines are a contour of another value) :
Is there something I'm missing in the way these functions work?
Got it!
Answer to the question is here :
x = self._tprun.r[0,p,::100] # re-sample every 100 values !!
y = self._tprun.r[1,p,::100] #
# [...]
#lc.set_array(self._color[p,:]) # self._color[p,:] is not resampled
lc.set_array(self._color[p,::100]) # this works because resampled
meaning that the 'color' array was actually much larger than the arrays used for position of the line segments.... only the first values of '_color' where used where its values do not vary that much.