11-16-2015 05:26 PM
Hi, i'm a new user. Sorry for my english, i'm brazilian.
I have this code attached and I need the code repeats N times. Where N is the number of images that I need to process. Every time the program start, I need that a new image to be processed and the data have to be write in a matrix. So each row of my final matrix has to contain the data processed. Until now in the VI i have two image being processed, but I'm rewriting all the code for each image. I want a looping where I have just write one time.
Someone can help me?
Solved! Go to Solution.
11-16-2015 06:47 PM
11-16-2015 11:54 PM
11-17-2015 01:34 AM
@jvc.dossantos wrote:
I have this code attached and I need the code repeats N times. Where N is the number of images that I need to process. Every time the program start, I need that a new image to be processed and the data have to be write in a matrix. So each row of my final matrix has to contain the data processed. Until now in the VI i have two image being processed, but I'm rewriting all the code for each image. I want a looping where I have just write one time.
As has been said, you really need to start with a few tutorials.
Converting to U8, then to a matrix, then to DBL (which it already is), then to a 2D array, then to a matrix indicator then back to a matrix and back to a 2D U8 array is pure madness. You can skip most of these steps, they simply don't make any sense. In LabVIEW, a matrix is a special typedef'd datatype most useful for lienar algebra. You are not doing linear algebra, so all you need are 2D arrays.
Also, typically if you have two arrays in the native U8 range , then multiply them, and convert the result back to U8, will cause a lot of data loss because of overflow. The product ot two U8 number can cover the full U16 range!
The result will probably not be very useful. Can you explain in more generic terms what you are trying to do?
How do you want the result to be arranged in the 2D array?
11-17-2015 01:36 AM
@GITA_A wrote:
..., and an insert into array function inside it.
The function "built array" is typically preferred over "insert into array" when simply appending.
11-17-2015 06:46 AM - edited 11-17-2015 06:47 AM
altenbach escreveu:
@jvc.dossantos wrote:
I have this code attached and I need the code repeats N times. Where N is the number of images that I need to process. Every time the program start, I need that a new image to be processed and the data have to be write in a matrix. So each row of my final matrix has to contain the data processed. Until now in the VI i have two image being processed, but I'm rewriting all the code for each image. I want a looping where I have just write one time.
As has been said, you really need to start with a few tutorials.
Converting to U8, then to a matrix, then to DBL (which it already is), then to a 2D array, then to a matrix indicator then back to a matrix and back to a 2D U8 array is pure madness. You can skip most of these steps, they simply don't make any sense. In LabVIEW, a matrix is a special typedef'd datatype most useful for lienar algebra. You are not doing linear algebra, so all you need are 2D arrays.
Also, typically if you have two arrays in the native U8 range , then multiply them, and convert the result back to U8, will cause a lot of data loss because of overflow. The product ot two U8 number can cover the full U16 range!
The result will probably not be very useful. Can you explain in more generic terms what you are trying to do?
How do you want the result to be arranged in the 2D array?
Sorry, I attached the wrong file. Now you can find the right.
I know that all that I did until now sounds like madness, but it worked. I want just some help to program my code better.
Basically, I have two images. The image that needs to be processed and a mask.
The first step is to convert each pixel of the images into an element of a matrix, then multiply (element by element) the both matrix.
After that I need eliminate all the Zeros of the new matrix and to convert it to a 1D matrix, creating a Non-Zeros Column Vector.
After all this process I need to create a new matrix with all the Non-Zeros Column Vector that I found. As you can see my VI already do all these steps.
But I need to do this for 28 images, and I'm repeating the code 28 times to make this work. And I now that is insane.
PS: It's not possible to attach bmp files, so I can't send you the images to you see what my program does
Can you help me?
11-17-2015 10:52 AM - edited 11-17-2015 10:53 AM
OK, so you have an array of images and an matching array of masks (or you can make an array out of the paths).
The images are 24bit RGB images and the masks are 4 bit images. Are the masks just 0 or 1?
When you convert a 24bit RGB image to U8, you are throwing away a singificant amount of information. What is the logic behind it?
In any case, if the mas is just 0,1, you can just multiply the two raw blue arrays. You don't need any orange of any kind anywhere. Drop all these meaningless conversions.
So you are transposing the 2D arrays and the reshape them to a 1D array and are removing all elements that are zero. Most likely, the two images you are processing contain a different amount of zeroed elements, so when you build these 1D arrays back into a 2D array with 2 rows (drop the matrix operations already!), the shorter array will get padded with zeroes. Is that really what you want?
At the end you are summing all the elements. Since the zero elements don't contribute to the sum, you don't really need to remove them so you can also skip the reshaping. Also transposing does not make a difference.
You end up with a 1D array, so why are you converting again to a matrix???
In any case, here's how you would process such arrays of matching images and mask paths, give about the same result (please verify!) as what you were doing. This should give you some ideas. As I said, converting a 24 bit RGB image to U8 seems incorrect. Modify as needed.
11-17-2015 08:00 PM
Yes, I have an array of image with the same size of my array of mask. And, yes, the mask it is just 0 or 1.
I know that I did some conversions of array to matrix that were unnecessary, now i can see and I did some changes. But in some steps when I let the data in array I couldn't see any number, all the values appear to me as zero and when I convert to matrix the data is shown. Why does this happen?
My images are 24bit RGB, however these images are in grayscale, so 0 is black and 255 is white. As I could see, when I just multiply directly, the values that I receive from that operation doesn't fit in the range between 0 to 255 and because of that my new image it's just a white square. But when I convert my image to U8 all the data remain in the range that I need and the new image is processed properly.
Then I have my 2D array, I transposed and reshaped to 1D, because I saw here in another post this tip.
In fact, I need that all the data of my 2D matrix to be willing in a 1D array and then eliminate all the possible zeroes.
In the end, i'm creating a new matrix composed by each 1D array non zero that I found.
In my case i have 28 images to process, so i will have 28 1D arrays and i will have a new 2D matrix with 28 columns.
In here I have a problem, because to do all that I'm repeating my code 28 times. And I want to know if it's possible to do this just one time for the number of images i want to process. Check out how it's my code until now.
11-17-2015 09:46 PM - edited 11-17-2015 10:52 PM
11-18-2015 07:50 AM
First of all, thanks for all your help, I know that all that I did until now is pure madness.
But, yes, I'm a new user. In fact, this is my first time in life using LabView and more I don't have almost any experience programming.
I'm second year college student of Agricultural Engineering and I had just a little bit of contact with C++ until now. This what i'm doing it's for my Scientific Initiation, it's a project it was given to me and I just have to figure out how to do, because my teacher has no clue how to do. So I'm sorry for all the trouble.
1. Ok, I'll just use 2D arrays since now
2. Yes, I know that what I did it's crazy, I knew that it would bother you! hahahah sorry. But in this case can I place all the code in just one FOR loop and the program will process the 28 different images with the masks that I need?
3. Ok.
4. Which is the correct way to do this conversion?
5. I use the color mask because in the time that I did this I saw in some tutorial video, when I did this my new image is shown to me, if I don't do this just appear a black square.
6. Yes, I saw your suggestion and because of that I eliminate unnecessary conversions that I was doing. Sorry, I couldn't understand properly the next part where you suggest what I should do. Can you explain with a VI?
7. I just saw many tutorials, on youtube, at this site and in the "help" of LabView, but this was the closest that I got
PS: What if I send to you the images and masks, and you compile the program to see what is happen? I believe this would clarify which is the best way to you help me .