Combine Thumbnails to One Large Image with RMagick [closed] - ruby

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
What's the shortest way to combine say 20 256x256 thumbnails into a single large image of 4 rows by 5 columns using RMagick?

Assuming all the images are in the current directory and named from 1.jpg to n.jpg and row * col = n.
include Magick
row = NUM_ROWS
col = NUM_COLS
ilg = ImageList.new
1.upto(col) {|x| il = ImageList.new
1.upto(row) {|y| il.push(Image.read((y + (x-1)*col).to_s + ".jpg").first)}
ilg.push(il.append(false))}
ilg.append(true).write("out.jpg")

Related

How to show more than 1 Stats panel in Three.js, side by side [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Only if it's possible; for example one panel for FPS and another one for MS
Thanks, best regards
Yes, you can have multiple:
var stats1 = new Stats();
stats1.showPanel(0); // Panel 0 = fps
stats1.domElement.style.cssText = 'position:absolute;top:0px;left:0px;';
document.body.appendChild(stats1.domElement);
var stats2 = new Stats();
stats2.showPanel(1); // Panel 1 = ms
stats2.domElement.style.cssText = 'position:absolute;top:0px;left:80px;';
document.body.appendChild(stats2.domElement);
And then in your main loop
stats1.update();
stats2.update();
stats.js r17

Transferring some parts of image [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to transfer some part of my image to another matrix with this code:
p1 = zeros(512,512,3);
p1(1:128, 1:128, 1:3) = image(1:128, 129:256, 1:3);
And when this code did not work I tried with 3 for loop
and after that I tried to transfer R G B layers separately:
p1(1:128, 1:128, 1) = image(1:128, 129:256, 1);
But none of these codes work. Could anyone tell me what to do?
In Matlab you can always assign one matrix to another with the same size. For example:
A = ones (4,2,3,4,5);
B = zeros(4,2,3,4,5);
A = B
will run with no errors.
It is possible that the type of the image you are using is uint8 (8-bit unsigned integer), while zeros creates a double matrix. This will result in improper behavior of operations or built-in functions, if you do not cast (change the type of) your matrices properly. Use whos to check the type of your image:
whos image
Try to cast the zeros to uint8:
p1 = uint8(zeros(512,512,3));
...
Here is an example:
image = imread('peppers.png');
partail_im = uint8(zeros(size(image)));
partail_im(1:128,1:128,:) = image(1:128,129:256,:);
imshow(partail_im);
Note: It's better not to use image as the name of any variable since it's name of a built-in function image.

Is XCode's auto-complete code misleading programmers? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
When I type "dispatch_after" in XCode, it auto-completes GCD code as below:
int64_t delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
<#code to be executed on the main queue after delay#>
});
let's look this statement :
int64_t delayInSeconds = 2.0;
int64_t is the synonyms of "long long",but here we assign a double value "2.0" to this kind of variable delayInSeconds.So the fractional part of the value will be discarded.If you assign it with value "0.3",the variable's value will be 0. I think this template of code will mislead programmers and the right code should be float delayInSeconds = 2.0;Am I right? thanks in advance.

What is this language? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
The source file is named "ReadOutputFile.m".
function ReadOutputFile(inputFile, outputFile)
SPIT = 2;
R_REGULARITY = 8;
%read input, threshold, and level
spitclip = wavread(inputFile);
spitclip = spitclip*(2^15);
fid = fopen('threshBinary.bin', 'rb', 'native');
thresh = fread(fid, 'int16');
fclose(fid);
fid = fopen('signalLevelBinary.bin', 'rb', 'native');
lvl = fread(fid, 'int16');
fclose(fid);
%get start and stop information from output file
outputNumeric = csvread(outputFile);
starts = outputNumeric(:,1);
stops = outputNumeric(:,2);
types = outputNumeric(:,8);
reasons = outputNumeric(:,9);
regularity = outputNumeric(:,7);
indicesOfSpits = find(types==SPIT);
numEvents = length(starts);
eventGate = zeros(1,length(spitclip));
firstSpits = zeros(1,length(spitclip));
chainedSpits = zeros(1,length(spitclip));
maxVal = 800;
%loop through events and plot spits only
%color code by reason
for n = 1:length(indicesOfSpits)
i = indicesOfSpits(n);
if(reasons(i) == R_REGULARITY)
chainedSpits(starts(i):stops(i)) = regularity(i)*800;
else
firstSpits(starts(i):stops(i)) = maxVal;
end
end
plot(spitclip);
hold on;
grid on;
plot(lvl,'r');
plot(thresh, 'y');
plot(firstSpits, 'm');
plot(chainedSpits, 'k');
That looks like Matlab (or the free equivalent octave)
http://en.wikipedia.org/wiki/M_(programming_language)
You would wonder, how easy it is to find the programming language.
By just knowing the suffix.

Color of the cars [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Could you give me a hint on how to solve this problem?
How can I find out whether most cars have the same color if the only function I can use is to check whether two cars have the same color?
With equality, you can first build equivalence classes and then count the largest one.
You can create a "list" where the color of the car is the key value and it counts how many cars of that color you have and stores a car of that color.
It goes something like this:
you will have a struct of with this fields:
struct color
car *car_with_color = NULL
int count = 0
so you go to the first car store it's color and add 1:
color[1].car_with_color=&cars[1];
color[1].count=1;
then for the next car you do:
if (cars[2].color == color[1].car_with_color->color)
color[1].count++;
else
color[2].car_with_color=&cars[2];
color[2].count=1;
and so on:
for (i=1;i<=NUM_OF_CARS;i++){
j=1;
while (color[j].car_with_color != NULL){
if (cars[i].color == color[j].car_with_color->color){
color[i].count++;
break;
}else
j++;
}
if (color[j].car_with_color == NULL){
color[j].car_with_color=&cars[i];
color[j].count=1;
}
}
it's written in a C like pseudo-code.

Resources