Here is my code but I’m trying to come up with a way to set the range from say 50% to 150% of the default font size.
<ul class="tags">
{#each tags as tag}
<li style={`font-size: ${(tag.count / tags[0].count) * 100 + 100}%;`}>
{tag.word} ({tag.count})
</li>
{/each}
</ul>
Let's say the font size base is 50% and your biggest font size is 150%.
We can have this formula 50 + (current tag count / total tag count)*100
Some scenarios:
Scenario 1
Tag 1 = 50
Tag 2 = 50
Total tags = 100
Tag 1's font size is (50+(50/100)*100)= 100 which is 100%
Tag 2's font size is (50+(50/100)*100)= 100 which is 100%
Scenario 2
Tag 1 = 50
Tag 2 = 90
Tag 3 = 20
Total tags = 160
Tag 1's font size is (50+(50/160)*100)= 81.25 which is 81.25%
Tag 2's font size is (50+(90/160)*100)= 106.25 which is 106.25%
Tag 3's font size is (50+(20/160)*100)= 62.5 which is 62.5%
Scenario 3
Tag 1 = 0
Tag 2 = 0
Tag 3 = 20
Total tags = 20
Tag 1's font size is (50+(0/20)*100)= 50 which is 50%
Tag 2's font size is (50+(0/20)*100)= 50 which is 50%
Tag 3's font size is (50+(20/20)*100)= 150 which is 150%
Does anyone know how to obtain the pixel value for each channel (RGB) from 16-bit tiff images using the magick package in R? Currently I am using Mathematica to perform this operation, because I could not find an equivalent way to doing it in mathematica.
I have tried to read the pixel value from the image-magick package and the results is a raw type (e.g. "ff"). I used the function rawToNum (package "pack") to convert the raw type to numeric and the results is close to what I obtain using ImageDate function in Mathematica, but not exactly the same.
You can also access the pixels as a numeric array with the magick package. The example is based on this vignette from the package.
library(magick)
tiger <- image_read('http://jeroen.github.io/images/tiger.svg')
tiger_tiff <- image_convert(tiger, "tiff")
# Access data in raw format and convert to integer
tiger_array <- as.integer(tiger_tiff[[1]])
Then if check the dimension and type you get:
dim(tiger_array)
[1] 900 900 4
is.numeric(tiger_array)
[1] TRUE
I don't know too much about R at all, but I guess you can "shell out" and execute an external command, using system() or somesuch.
If, so, maybe you can use this. First, let's make a 16-bit TIFF file that is a gradient from red-blue just 10 pixels wide and 1 pixel tall:
convert -size 10x1 gradient:red-blue image.tiff
Now we can dump the pixels to a file using ImageMagick:
convert image.tiff rgb:image.rgb
# Now check its length - yes, 60 bytes = 10 pixels with 2 bytes each for RG &B
ls -l image.rgb
-rw-r--r-- 1 mark staff 60 11 Jul 10:32 image.rgb
We can also write the data to stdout like this:
convert image.tiff rgb:-
and also look at it with 1 pixel per line (6 bytes)
convert image.tiff rgb:- | xxd -g 3 -c 6
00000000: ffff00 000000 ...... # Full Red, no Green, no Blue
00000006: 8de300 00721c ....r. # Lots of Red, no Green, a little Blue
0000000c: 1cc700 00e338 .....8
00000012: aaaa00 005555 ....UU
00000018: 388e00 00c771 8....q
0000001e: c77100 00388e .q..8.
00000024: 555500 00aaaa UU....
0000002a: e33800 001cc7 .8....
00000030: 721c00 008de3 r.....
00000036: 000000 00ffff ...... # No Red, no Green, full Blue
I'm hoping you can do something like that in R, with:
system("convert image.tif rgb:-")
Another way of dumping the pixels might be with Perl to slurp the entire file and then unpack the contained unsigned shorts and print them one per line:
convert image.tiff rgb: | perl -e 'my $str=do{local $/; <STDIN>}; print join("\n",unpack("v*",$str)),"\n";'
Sample Output
65535 # Full Red
0 # No Green
0 # No Blue
58253 # Lots of Red
0 # No Green
7282 # A little Blue
50972 # Moderate Red
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0 # No Green
58253 # Lots of Blue
0 # No Red
0 # No Green
65535 # Full Blue
Another way of seeing the data may be using od and awk like this:
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535
where the -An suppresses printing of the address, and the -tuS says the type of the data is unsigned short.
Perhaps a slightly simpler way in ImageMagick would be to use the txt: output format.
Using Mark Setchell's image:
convert -size 10x1 gradient:red-blue image.tiff
Using TXT: as
convert image.tiff txt: | sed -n 's/^.*[(]\(.*\)[)].*[#].*$/\1/p'
Produces:
65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
or Using TXT: to include the pixel coordinates
convert image.tiff txt: | sed -n 's/^\(.*[)]\).*[#].*$/\1/p'
Produces:
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)
Thank you all. The best answer I found was given by a student of mine using the package raster:
library(raster)
img <- stack(filename)
x <- as.matrix(raster(img, 1)) # here we specify the layer 1, 2 or 3
The only issue is that the function as.matrix of the package raster may be confused with the one from the base package, so it may be necessary to specify raster::as.matrix.
#Nate_A gave the answer, but three cents short of a dollar.
After
dim(tiger_array)
[1] 900 900 4
You get each channel color of first pixel by
tiger_array[1,1,1] # red
tiger_array[1,1,2] # green
tiger_array[1,1,3] # blue
Or if you prefer between 0 - 255
tiger_array[1,1,1]*255
tiger_array[1,1,2]*255
tiger_array[1,1,3]*255
I have created heatmap graphs using gnuplot.
I have data.dat:
avail reli perf
stop 181 20 121 10 34 20
jitter 18 20 17 20 13 20
limp 12 20 5 30 20 20
and gnuplot script:
set term pos eps font 20
unset key
set nocbtics
set cblabel "Score"
set cbtics scale 0
set cbrange [ 0.00000 : 110.00000 ] noreverse nowriteback
set palette defined ( 0.0 "#FFFFFF",\
1 "#FFCCCC",\
20.2 "#FF9999 ",\
30.3 "#FF6666",\
40.4 "#FF3333",\
50.5 "#FF0000",\
60.6 "#CC0000",\
70.7 "#C00000",\
80.8 "#B00000",\
90.9 "#990000",\
100.0 "#A00000")
set title "Faults"
set ylabel "Hardware Faults"
set xlabel "Aspects"
set size 1, 0.5
set output 'c11.eps'
YTICS="`awk 'BEGIN{getline}{printf "%s ",$1}' 'data2.dat'`"
XTICS="`head -1 'data2.dat'`"
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) i-1 )
set for [i=1:words(YTICS)] ytics ( word(YTICS,i) i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix w image, '' matrix using 1:2:($3==0 ? " " : sprintf("%.1d",$3)) with labels
#######^ replace the first field with nothing
################################## ^ delete first line
My output is:
Here I have range 1-20,30-39,...,100 or more)
Now I have to 2 values in every axis. e.g stop and avail have(181 and 20). the 181 is the count and 20 is percentages. I want to create graphs which have colors base on percentages and the labels on my graphs from the counts of data.
I have experienced create some graph using for and do some modulo to select the data. But here, I have not idea to create that graphs. Any suggestion for creating this? Thanks!
You can use every to skip columns.
plot ... every 2 only uses every second column, which is what you can use for the labels. For the colors, you must start with the second column (numbered with 1), and you need every 2::1.
Following are the relevant changes only to your script:
set for [i=1:words(XTICS)] xtics ( word(XTICS,i) 2*i-1 )
plot "<awk '{$1=\"\"}1' 'data2.dat' | sed '1 d'" matrix every 2::1 w image, \
'' matrix using ($1+1):2:(sprintf('%d', $3)) every 2 with labels
The result with 4.6.5 is:
i am given a frame and i try to put a scrollable canvas into it.
everything seems to work fine and i get scrollbar but they dont seem to work.
scrollbar does expand and contract when i resize window and does move when i click on its bottom or top.
for frame .f and canvas .f.c
my yview output changes when i try to scroll
i.e
.f.c yview
.08 .35
.f.c yview
.38 .62
.f.c yview
.75 1
i am not sure what have i missed here?
frame .f
canvas .f.c
put few labels
place them
scrollbar .f.ysb -orient vertical -command ".f.c yview"
.f.c configure -yscrollcommand ".f.ysb set" -scrollregion [list -1000 -1000 1000 1000]
grid .f.c -row 0 -column 0 -sticky nsew
grid .f.ysb -row 0 -column 1 -sticky ns
grid columnconfigure .f 0 -weight 1
grid rowconfigure .f 0 -weight 1