infile code example problem

14 views (last 30 days)
phedon GIALIS
phedon GIALIS on 19 May 2014
Commented: Image Analyst on 21 May 2014
Hallo,im new to matlab,i found this example http://www.mathworks.com/products/matlab-coder/code-examples.html?file=/products/demos/shipping/coder/coderdemo_gr.html and i want to make a small video about 50 frames,to see how it will be shown a black hole with a rotating point of view,but the function can not take any more than 1 infile,is there any way to put more files,than to put each one and then save them, Thank you

Answers (3)

Image Analyst
Image Analyst on 20 May 2014
See attached demo for how to create a video file from a bunch of saved images.
  4 Comments
Image Analyst
Image Analyst on 20 May 2014
phedon's second "Answer" moved here:
Ok,but there wasn't any answer in the first question about inserting many infiles than one each time and after making the render for each,saving it. the code just takes one infile each time and then i have to save it manual.I tried the kode with the k = 1:len(imagefiles) with many variasions,but then just reads the pictures,or says me tha the infile takes just one argument or tha there is problem with assertions.Maybe i must make a for loop for each image in the array is infile then the function and save.I tried some code in that but there was no success.I think if i find the first one the saving is easy
Image Analyst
Image Analyst on 20 May 2014
I'm not sure I understand that even after reading it many times. What is an infile? Why does an infile take "just one argument" or even any arguments at all? Is an infile a function? What does it mean if "the array is infile"? I have no idea. You say you "then the function and save" - what function are you talking about?
You say "if i find the first one" but what does "one" refer to? And how are you doing the "find"?
What do you mean by "assertions"? I don't think you're using it with the standard English definition.
Why are your images "in an array"? Do you have a 3D image? Do you have a cell array?
I just don't understand enough of what you said to even answer. Perhaps get a native English speaker to review it.

Sign in to comment.


phedon GIALIS
phedon GIALIS on 21 May 2014
Sorry if was missunderstood,This code renders one picture at a time.i would like to run with multiple images while save them automatically. Thank you
function gr_raytrace(infile) %#codegen
% Copyright 2010 The MathWorks, Inc.
% We apply assertions on the inputs (instead of specifying example arguments) % As this program does not require dynamic memory allocation in general, we % apply constraints on the size of the input string. assert(isa(infile, 'char')); assert(size(infile,1) == 1); assert(size(infile,2) <= 1024);
coder.extrinsic('disp','figure','imread','image','get','set','gca','error','mat2cell');
% If the first character of the path is a '-' character, we interpret it as % a rescaling operation. rescaleImage = infile(1) == '-'; if rescaleImage infile = infile(2:end); end
% Put maximum bounds on the images, as we'd like to compile this program % without the need for dynamic memory allocation. coder.varsize('inImage', [2048 2048 3]); coder.varsize('outImage', [2048 2048 3]); % Initialize inImage before calling the extrinsic function. MATLAB Coder % cannot analyze extrinsic functions, so we force the return type of the % function using this trick. inImage = zeros(0,0,3,'uint8'); inImage = imread(infile);
% Rescale image if necessary if rescaleImage if size(inImage,1) > 512 size(inImage,2) > 512 maxSz = max(size(inImage,1),size(inImage,2)); newH = (size(inImage,1)/maxSz)*512; newW = (size(inImage,2)/maxSz)*512; inImage = shrinkImage(inImage, newW, newH); end end
% Setup figure windows origFig = figure; set(origFig, 'Position', [32 64 size(inImage, 2) size(inImage,1)]); set(origFig, 'Name', 'Original Picture'); image(inImage); set(gca, 'Visible', 'off'); set(gca, 'Position', [0 0 1 1]);
rayFig = figure; origPos = [0 0 0 0]; origPos = get(origFig, 'Position'); xpos = origPos(1) + origPos(3) + 8; ypos = origPos(2); set(rayFig, 'Position', [xpos ypos size(inImage,2) size(inImage,1)]); set(rayFig, 'Name', 'Ray-traced with Black Hole'); context.image = 0; context.outImage = inImage; context.image = image(inImage); set(gca, 'Visible', 'off'); set(gca, 'Position', [0 0 1 1]);
% Apply raytracing and a progress call back function gr_raytrace_image(inImage, @progress, context);
% This sub-function will be called periodically within the raytracing % function. Each time we render what we've got so far. function progress(context, y, height) %#ok coder.extrinsic('set', 'drawnow'); set(context.image, 'CData', context.outImage); drawnow;
% Sub-function to shrink an image. We compute the average color value % by looking at surrounding colors at each pixel. This gives a much % better image quality (a technique known as anti-aliasing). function im2 = shrinkImage(im, newW, newH) % Never inline this function to improve code readability when doing code % generation. coder.inline('never'); assert(isa(im, 'uint8')); assert(size(im,1) <= 2048); assert(size(im,2) <= 2048); assert(size(im,3) <= 3); assert(newW <= 512); assert(newH <= 512); im2 = zeros(newH, newW, size(im,3), class(im)); h = size(im,1); w = size(im,2); for y = 1:newH y0 = int32(h*(y-1)/newH + 1); y1 = int32(h*(y)/newH + 1); if y1 > h, y1 = int32(h); end for x = 1:newW x0 = int32(w*(x-1)/newW + 1); x1 = int32(w*(x)/newW + 1); if x1 > w, x1 = int32(w); end cnt = 0; v = zeros(1,1,size(im,3),'int32'); for i = y0:y1 for j = x0:x1 v = v + int32(im(i,j,:)); cnt = cnt + 1; end end im2(y,x,:) = v/cnt; end end

phedon GIALIS
phedon GIALIS on 21 May 2014
and the code that i made is inside the first function,i deleted the assert,is this
function gr_raytrace(i) %#codegen
% Copyright 2010 The MathWorks, Inc.
% We apply assertions on the inputs (instead of specifying example arguments) % As this program does not require dynamic memory allocation in general, we % apply constraints on the size of the input string.
myFolder = 'C:\Users\Phaidon\Documents\MATLAB\r'; if ~isdir(myFolder) errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder); uiwait(warndlg(errorMessage)); return; end filePattern = fullfile(myFolder, '*.jpg'); jpegFiles = dir(filePattern); for i = 1:length(jpegFiles) i = i
end
coder.extrinsic('disp','figure','imread','image','get','set','gca','error','mat2cell');
  1 Comment
Image Analyst
Image Analyst on 21 May 2014
I have no idea. It requires toolboxes I don't have.

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!