Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    Replace

    the respective section in the loop by


    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-floor((N-48)/100)-48)/10)+48, N-(floor((N)/100))*100-(floor((N-floor((N)/100))/10))*10+48];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    and check if it works now? (You'll have to delete the files that are gray before you do this.)



    ive just did that mate

    > in Matlab at 34
    im getting the warning ut of range or non-integer values trunacated during conversation to character


    Error using ===> imwrite at 409
    cant open file "cam2_loop_gray_1:" for writing.
    you may not have permision


    Error in ===> matlab at 35
    imwrite(G(:,:,n),newName);



    although i have noticed its now changed 60 images
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    Replace

    the respective section in the loop by


    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-floor((N-48)/100)-48)/10)+48, N-(floor((N)/100))*100-(floor((N-floor((N)/100))/10))*10+48];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    and check if it works now? (You'll have to delete the files that are gray before you do this.)



    ive just did that mate

    > in Matlab at 34
    im getting the warning ut of range or non-integer values trunacated during conversation to character


    Error using ===> imwrite at 409
    cant open file "cam2_loop_gray_1:" for writing.
    you may not have permision


    Error in ===> matlab at 35
    imwrite(G(:,:,n),newName);



    although i have noticed its now changed 60 images :woo:
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    cheers mate

    am not getting an error typing the above in

    newName=cam2_loop_gray111.bmp


    by the way what is it ive just typed ?
    You mean

    newName=cam2_loop_gray111.bmp

    ? I'm actually surprised that worked, it should be in ' ' for it to work (as it is a string)
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    ive just did that mate

    > in Matlab at 34
    im getting the warning ut of range or non-integer values trunacated during conversation to character


    Error using ===> imwrite at 409
    cant open file "cam2_loop_gray_1:" for writing.
    you may not have permision


    Error in ===> matlab at 35
    imwrite(G(:,:,n),newName);



    although i have noticed its now changed 60 images :woo:

    OK, there was a mistake, try replacing it by this:


    Replace

    the respective section in the loop by

    %save to originalName_gray_*.bmp, where * goes from 001 to numFrames
    %numbering of the new files
    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-(floor((N)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N)/100))*100-48)/10)*10];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    and check if it works now? (You'll have to delete the files that are gray before you do this.)
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    You mean

    newName=cam2_loop_gray111.bmp

    ? I'm actually surprised that worked, it should be in ' ' for it to work (as it is a string)

    yeah it worked never had any errors or warnings

    but after i amended your second code i received maybe 35 warnings and the two errors

    > in Matlab at 34
    im getting the warning ut of range or non-integer values trunacated during conversation to character


    Error using ===> imwrite at 409
    cant open file "cam2_loop_gray_1:" for writing.
    you may not have permision


    Error in ===> matlab at 35
    imwrite(G(:,:,n),newName);
    Offline

    14
    ReputationRep:
    (Original post by azzi)


    although i have noticed its now changed 60 images :woo:
    Sorry, I made another mistake, you have to take this:


    %save to originalName_gray_*.bmp, where * goes from 001 to numFrames
    %numbering of the new files
    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-(floor((N-48)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N-48)/100))*100-48)/10)*10];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    The problem was that "num" was ****** up because I had a wrong calculation in there, but it should be fixed now. I bet there is an easier way to do this..
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    im getting the warning ut of range or non-integer values trunacated during conversion to character
    btw, this was the hint that num was ****** up

    char(num) converts num to a character array, that wasn't working. hope it's working now



    and btw, (just for future, may be helpful to you), if you get several errors, it is always the first one that is the real problem, the others are most of the time just consequences of the first error.
    Offline

    19
    ReputationRep:
    I'm sorry I can't be of any help, but I am strongly reminded of: http://matlabmadness.ytmnd.com/

    It sounds like a horrible language to program in.
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    OK, there was a mistake, try replacing it by this:


    Replace

    the respective section in the loop by

    %save to originalName_gray_*.bmp, where * goes from 001 to numFrames
    %numbering of the new files
    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-(floor((N)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N)/100))*100-48)/10)*10];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    and check if it works now? (You'll have to delete the files that are gray before you do this.)


    Error using ===> imwrite at 409
    cant open file "cam2_loop_gray_0+:" for writing.
    you may not have permision


    Error in ===> matlab at 36
    imwrite(G(:,:,n),newName);


    i deleted the gray images and its actually only converted 50 images compared to 59 using the previous code
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    i deleted the gray images and its actually only converted 50 images compared to 59 using the previous code
    Yes I meanwhile had discovered another mistake in num (see last before last post above).. sorry about this

    So, replace the num line by

    num=[floor((N-48)/100)+48, floor((N-(floor((N-48)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N-48)/100))*100-48)/10)*10];
    Offline

    14
    ReputationRep:
    (Original post by Sweyn Forkbeard)
    I'm sorry I can't be of any help, but I am strongly reminded of: http://matlabmadness.ytmnd.com/

    It sounds like a horrible language to program in.
    Matlab is actually amazing.

    It's just weird to explain over the internet and I'm selftaught so I probably do some not so very efficient things...

    BTW, movie doesn't work for me..?
    Offline

    19
    ReputationRep:
    Try refreshing, or using a different browser.

    The idea of a numeric language makes me go :lolwut:.
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by Sweyn Forkbeard)
    Try refreshing, or using a different browser.

    The idea of a numeric language makes me go :lolwut:.


    it makes me go like that aswell but needs must

    wish i had been taught matlab in first or second year life would be soo much easier
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    Yes I meanwhile had discovered another mistake in num (see last before last post above).. sorry about this

    So, replace the num line by

    num=[floor((N-48)/100)+48, floor((N-(floor((N-48)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N-48)/100))*100-48)/10)*10];

    your a ******* legend

    Thats all the pics converted :woo:

    if i could i would jump through this laptop and kiss you
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    your a ******* legend

    Thats all the pics converted :woo:

    if i could i would jump through this laptop and kiss you
    No problem, makes me happy too.

    If you want you can make it more efficient by pre-allocating space for G, having only one loop and cut out the anim if you don't need the animation.
    • Thread Starter
    Offline

    1
    ReputationRep:
    (Original post by llys)
    Sorry, I made another mistake, you have to take this:


    %save to originalName_gray_*.bmp, where * goes from 001 to numFrames
    %numbering of the new files
    N=48+n;
    num=[floor((N-48)/100)+48, floor((N-(floor((N-48)/100))*100-48)/10)+48, N-floor((N-48)/100)*100-floor((N-(floor((N-48)/100))*100-48)/10)*10];
    %to get the filename you want, get the numbers with uint8('yourName'),
    %and then put num in the place where the file number should be,
    %right now the new names are cam2_loop_gray_001 to 500 etc.
    newName=char([99 97 109 50 95 108 111 111 112 95 103 114 97 121 95 num 46 98 109 112]);
    imwrite(G(:,:,n),newName);


    quick question where are you getting they numbers from ? or what do they represent ? just so that i can make a note of them in future if i need to this again
    Offline

    14
    ReputationRep:
    (Original post by azzi)
    quick question where are you getting they numbers from ? or what do they represent ? just so that i can make a note of them in future if i need to this again
    OK let's say you you want to create a filename that is going to be

    filename_567.bmp

    so you have to create a character array that contains

    filename_567.bmp

    A character array uses characters... erm that's kind of hard to explain, but you can see what I mean when you try out this: type

    uint8('filename_')

    this returns an array of numbers that represent the characters in filename_ (f is represented by a number, i is represented by a number, and so on - for every character, one number).
    if you type

    char(uint8('filename_'))

    this returns filename_

    Now the problem with the filenames is that the numbers increase from 1 to 500 and you can't define 500 different filenames, i.e. you want to determine the varying filenames in one definition inside the loop. this is where num comes in. in uint8 speak,

    uint8('0')

    returns 48. that is

    char(48)

    returns 0.

    char(49)

    returns 1.

    uint8('567')

    returns three numbers in character speak, probably [53 54 55].

    char([53 54 55])

    returns 567.

    Since 48==>0, I define N=48+n. (This is actually completely unnecessary as you could just use n in num).
    num in the code calculates the uint8 values for the current N of the loop. the first number in num, i.e.

    floor((N-48)/100)+48

    is the number of 100s that go into n (the + 48, is so that char(floor((N-48)/100)+48) returns the right value, since 48==>0). For n=567 that should return 5+48=53, and char(53)=5... the second number in num is the number of 10s that go into n +48, and the last is the number of 1s+48. So n=567 would be converted into num=[53 54 55]. Because now you determine num based on the value of n, you can calculate the characters for the numbers in the filename, and then you can create the complete filename by

    newName=char([uint8('filename_') num uint8('.bmp')])

    That way inside the loop for every n it will create a new filename with an increasing file number inside the filename. The numbers I put in newName=char() are representing the characters for cam2_loop_gray etc..

    What was messed up was that I made a mistake calculating the numbers in num, so the char conversion didn't work. For example, char(-50) is not defined and will give you one kind of error. A mistakenly produced * character in the filename will try to open the file before writing it, which gives you another kind of error if the file doesn't exist. and so on.




    Maybe, just possibly, you could cut all this crap and just write

    newName=char([uint8('filename_') uint8(n) uint8('.bmp')])

    that would make me feel quite stupid. However I'm not sure that uint8 takes numbers as argument (i.e. '567' is a string, not a number, whereas 567 is a number) so that might not have worked anyway...





    ---------------------

    Another much easier way to do this (not using the num thing) is to say

    newName=char([uint8('gray_') uint8(fileNames{n})]);

    this means the new file name will be the old filename with a prefix gray_; no calculations needed.
    • Thread Starter
    Offline

    1
    ReputationRep:
    me again

    ive got another problem i was hoping you could help me with
    basically i the pics i had i could work on a certain area by typing in a some code so that it would zoom in on a certain area but whenever i try to do that to the grayscale pics i get

    " index exceeds matrix dimensions "

    i checked the dimensions and by original pics are
    240 320 3

    but the greyscale pics are
    240 320

    is there anyway i could change the size ?

    the code i used was

    imshow(I(:,:,2))

    so basically i want to change a 2D array to 3D array
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: January 20, 2010
Poll
Do you agree with the PM's proposal to cut tuition fees for some courses?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.