Principal Component-Based Image Processing

Source: Internet
Author: User

It mainly solves the number in a graph and how to flexibly change the number to achieve the goal of changing the number.

The most important thing is to use the cellular array. For example, Im is a 16*20 cellular array, and the number of each cellular is 16*16*3. How can we arrange 768 of each cell in a row in order?

Im is transformed into a matrix of 320*728. Each row represents a cell.


Before getting started with the cellular array, I could naturally think of two for loops:

A = [];
T = 1;
For J = 1:20
For I = 1:16
A (t, :) = Im {I, j }(:);
T = t + 1;
End
End

In this way, a is required.

Although the Code of the For Loop is simple and saves your own troubles, it is not worth it because it gives the difficulties to the computer and the time is used to change the troubles!


If you do not need a for loop, you can use the cellular array:

Im_1 = CAT (4, Im {:});

Im_2 = reshape (im_1, [16*16*3, 16*20]) ';

In this way, im_2 is required, that is, it is equal to the phase.

I always think that through various conversions, errors will occur if you don't have to worry about it. For example, if you write

Im_1 = CAT (4, Im {:});

Im_22 = reshape (im_1, [16*20, 16*16*3]);

In this way, im_22 is the same as im_1 through whos, but in fact, the returned value of isequal (im_1, im_22) is 0.
So be careful. Otherwise, you will not even know what is wrong.

Finally, clock is used to test the running time of the above two methods:


T1 = clock;

A = [];
T = 1;
For J = 1:20
For I = 1:16
A (t, :) = Im {I, j }(:);
T = t + 1;
End
End

T2 = clock;

Waiting = t2-t1;

The displayed result is waiting1 = 0.056.


Using the cellular array:
T1 = clock;

Im_1 = CAT (4, Im {:});

Im_2 = reshape (im_1, [16*16*3, 16*20]) ';

T2 = clock;

Waiting2 = t2-t1;

In this case, waiting2 is 0.004;


Compared with waiting1 and waiting2, you can easily find a 10-fold difference.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.