Prev: Portable Excel files using Spreadsheet Link EX
Next: Constrain imdistline endpoints to two lines
From: Parker on 19 Feb 2010 18:13 after reading an image to a variable A, I met an error of "Indexing cannot yield multiple results" when I want to assign the r, g, b components to 3 varaiables like: [r,g,b] = A(1,1,:) ================== due it's a long loop, so I want to save the r,g,b components to speed up the function. Is there any way for me to do that? "r = A(1,1,:); g=A(1,1,2);b=A(1,1,3);" is not the answer I want, because it has to fetch values from the image array 3 times. Thanks in advance.
From: James Tursa on 19 Feb 2010 18:21 Parker <xenoszh(a)gmail.com> wrote in message <764ee50d-dcdb-452e-aa43-a3b06481669d(a)g19g2000yqe.googlegroups.com>... > after reading an image to a variable A, I met an error of "Indexing > cannot yield multiple results" when I want to assign the r, g, b > components to 3 varaiables like: > > [r,g,b] = A(1,1,:) > ================== > due it's a long loop, so I want to save the r,g,b components to speed > up the function. > Is there any way for me to do that? > > "r = A(1,1,:); g=A(1,1,2);b=A(1,1,3);" is not the answer I want, > because it has to fetch values from the image array 3 times. > > Thanks in advance. How is the r-g-b info actually stored? Your example code doesn't make sense to me. Are the r,g,b values interleaved in memory? If so, then a simple c-mex routine can generate the separate variables by accessing the original array only once. Let me know. James Tursa
From: Walter Roberson on 19 Feb 2010 18:18 Parker wrote: > after reading an image to a variable A, I met an error of "Indexing > cannot yield multiple results" when I want to assign the r, g, b > components to 3 varaiables like: > > [r,g,b] = A(1,1,:) > ================== > due it's a long loop, so I want to save the r,g,b components to speed > up the function. > Is there any way for me to do that? > > "r = A(1,1,:); g=A(1,1,2);b=A(1,1,3);" is not the answer I want, > because it has to fetch values from the image array 3 times. I could provide code that could do it, but it would be less efficient than the individual assignments. r = A(:,:,1); b = A(:,:,2); g = A(:,:,3); When the first two dimensions are allowed to vary and the third is fixed, then the data extracted comes from a sequential block of memory and would be written in a sequential block in exactly the same order -- the most efficient memory copying operation that there is. The alternatives that we could provide could do the assignments to [r,g,b] in a single line, but for syntactic reasons a temporary variable would be required, and it would be necessary to copy the original data into the temporary variable.
From: Parker on 20 Feb 2010 03:53 On Feb 19, 11:21 pm, "James Tursa" <aclassyguy_with_a_k_not_...(a)hotmail.com> wrote: > Parker <xeno...(a)gmail.com> wrote in message <764ee50d-dcdb-452e-aa43-a3b064816...(a)g19g2000yqe.googlegroups.com>... > > after reading an image to a variable A, I met anerrorof "Indexing > > cannot yield multiple results" when I want to assign the r, g, b > > components to 3 varaiables like: > > > [r,g,b] = A(1,1,:) > > ================== > > due it's a long loop, so I want to save the r,g,b components to speed > > up the function. > > Is there any way for me to do that? > > > "r = A(1,1,:); g=A(1,1,2);b=A(1,1,3);" is not the answer I want, > > because it has to fetch values from the image array 3 times. > > > Thanks in advance. > > How is the r-g-b info actually stored? Your example code doesn't make sense to me. Are the r,g,b values interleaved in memory? If so, then a simple c-mex routine can generate the separate variables by accessing the original array only once. Let me know. > > James Tursa the image was read as A = imread('test.jpg'), the A(:,:,1), A(:,:,2) and A(:,:,3) was the 3 components of R, G and B. due to I need to fetch the R, G, B values at a specified position within a rather long loop, I want to get them at the same time like [r,g,b]=A(i,j,:), unfortunately it didn't work. I think I need to try other ways to modify the algorithm to avoid the long loop.
From: Parker on 20 Feb 2010 04:07 On Feb 19, 11:18 pm, Walter Roberson <rober...(a)hushmail.com> wrote: > Parker wrote: > > after reading an image to a variable A, I met anerrorof "Indexing > > cannot yield multiple results" when I want to assign the r, g, b > > components to 3 varaiables like: > > > [r,g,b] = A(1,1,:) > > ================== > > due it's a long loop, so I want to save the r,g,b components to speed > > up the function. > > Is there any way for me to do that? > > > "r = A(1,1,:); g=A(1,1,2);b=A(1,1,3);" is not the answer I want, > > because it has to fetch values from the image array 3 times. > > I could provide code that could do it, but it would be less efficient than the > individual assignments. > > r = A(:,:,1); b = A(:,:,2); g = A(:,:,3); > > When the first two dimensions are allowed to vary and the third is fixed, then > the data extracted comes from a sequential block of memory and would be > written in a sequential block in exactly the same order -- the most efficient > memory copying operation that there is. > > The alternatives that we could provide could do the assignments to [r,g,b] in > a single line, but for syntactic reasons a temporary variable would be > required, and it would be necessary to copy the original data into the > temporary variable. thx, for optimizing purpose, it's better to do the assignments in separate line, if there's no way to avoid getting values for 3 times.
|
Next
|
Last
Pages: 1 2 Prev: Portable Excel files using Spreadsheet Link EX Next: Constrain imdistline endpoints to two lines |