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.
Related
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
Using example Test Sheet
Looking to use script in Sheets to;
Read active sheet name [e.g. RED]
Look in SUMMARY Sheet and find matching sheet name in column A and read associated integer [e.g. R1C2]
Multiply that by RED R1C1 and display result in RED R1C2
I would want to be able to do this for all values in column 1 in RED, GREEN & BLUE sheets, either on opening or by using a button
Any pointers would be greatly appreciated!
Your question has been voted down as you haven't shown any research or posted any of your own code. I'll help you out as I too am new here ;-). It is good that you have broken your request down, the next step would have been to start writing code... The following code will do what you have requested, bar it on running on open or by using a button. My advice to getting started with Apps Script would be to read through the reference documents and samples so that you understand fully what the code does.
function myFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeSheet = ss.getActiveSheet();
var activeSheetName = activeSheet.getSheetName();
var activeSheetData = activeSheet.getDataRange().getValues();
var summarySheet = ss.getSheetByName("SUMMARY");
var summarySheetData = summarySheet.getDataRange().getValues();
for (var i = 0; i < summarySheetData.length; i++) {
if (summarySheetData[i][0] == activeSheetName) {
valueToMultiplyBy = summarySheetData[i][1];
}
}
for (var j = 0; j < activeSheetData.length; j++) {
var resultOfMultiplication = valueToMultiplyBy * activeSheetData[j][0];
activeSheet.getRange(j+1,2).setValue(resultOfMultiplication);
}
}
This question already has an answer here:
How to create movies on each generation of a for loop in Matlab plot
(1 answer)
Closed 9 years ago.
I have the following code:
figure;
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
EDIT
figure;
for i = 1: G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
end
NB: G is the maximum generation.
This is supposed to plot contours of sphere superimposed with selected individuals. In each iteration of the individuals, the best individuals is selected and these going on until the global optimum is reached. I need to show this in a movie form as shown in this below:
When you runs each stage of the iteration is indicated in the slides attached. This is what i am trying to do. Any idea please?
OK, I am just copying and pasting now, from here.
However I added FrameRate (per second) since you might want to use (or ask) it later.
writerObj = VideoWriter('Your_video.avi');
writerObj .FrameRate = 1; % 1 frames per second animation.
open(writerObj);
fig_h = figure;
for i = 1: G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
writeVideo(writerObj, frame);
end
close(writerObj);
Now you will have a Your_video.avi file in your working directory.
If VideoWriter is not supported by your matlab, you could use use avifile same as mentioned in this answer (or in mathwork documentaion example here) like this:
aviobj = avifile('Your_video.avi','compression','None', 'fps', 1);
fig_h = figure;
for i = 1:G
contour(X1,X2,f);
hold on
plot(top(1:size(top,1)), 'rx');
frame = getframe(fig_h); % or frame = getframe; since getframe gets gcf.
aviobj = addframe(aviobj, frame);
end
aviobj = close(aviobj);
EDIT
A problem may occur as pointed out by this question also, which is the captured frame is a constant image. If you are running Matlab on windows, this problem may be caused by conjunction of windows in with certain graphics drivers, and may be solved as mentioned in this answer.
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.
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.
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")