How to change the bit width of destination port?

  • I'm trying to use the 'rollingAverage_Loop'(VisualApplets_3.1\Examples\Processing\Loop\RollingAverage) to calculate the sum of squares of multiple images.


    In order to make my design run sucessfully, I added an operator-CastBitWidth(squares/StartUp_SUB_1/CastBitWidth) to change the bitwidth from 16 to 8.Right now, I set the N_rolling to 5,and I can see the results of the first four images' processing are the same as expected,but I found that the result of other image processing is not the same as expected.I think that is because I changed the bitwidth before,so I want to know how to change the bitwidth of destination port to keep the bitwidth with 16.Or maybe there's other solution?

    Hope to get the solution as soon as possible.Thank you very much.

  • Dear Danna,

    thank you for your question.

    If you want to change the Init Value in module "StartUp_Value" from 16 Bit Value to 8 Bit Value: Please also change in module "cast" the ClipHigh" value to 255 and "castBitWidth" to 8 Bit and adapt in module "dynamicDivider" the Bit depth of the Const operators to less/equal than 8 Bit.

    best regards


  • Dear Danna,

    before changing from higher bit depth to lower bit width with operator "CastBitWidth" I always recommend to use operator "ClipHigh" before. This operators sets all input values above a defined maximum to the maximum value.

    If you are completely sure that your input values do not exceed 255 (= 8 Bit range) the ClipHigh operator is not necessary.

  • Dear Carmen Z,

    Thank you for your reply.

    I want to do pseudo color processing on gray images. Color model refers to the jet color model in MATLAB. This is the function of jet color model in MATLAB.

    %function J = jet(m)

    % if nargin < 1

    % m = size(get(gcf,'colormap'),1);

    % end

    % n = ceil(m/4);

    % u = [(1:n)/n ones(1,n-1) (n:-1:1)/n]';

    % g = ceil(n/2) - (mod(m,4)==1) + (1:length(u))';

    % r = g + n;

    % b = g - n;

    % g(g>m) = [];

    % r(r>m) = [];

    % b(b<1) = [];

    % J = zeros(m,3);

    % J(r,1) = u(1:length(r));

    % J(g,2) = u(1:length(g));

    % J(b,3) = u(end-length(b)+1:end);


    Because I don't know much about the jet function in MATLAB, and I'm not sure if I can simulate the jet function in the visual applet, I also plan to use a simple function conversion for pseudo color processing.

    Input a gray image, for each pixel I (I, J), judge the pixel whose gray value is less than 64, transform according to r = 0, g = 4 * I (I, J), B = 255; for the pixel whose gray value is greater than 63 and less than 128, transform according to r = 0, g = 255, B = 255-4 * [I (I, J) - 128]; for the pixel whose gray value is greater than 127 and less than 192, transform according to r = 4 * [I (I, J) - 128], G= 255, B = 0 for transformation; for pixels with gray value greater than 191, according to r = 255, g = 255-4 * [I (I, J) - 192], B = 0 for transformation.

    I tried to write a pseudo color VA file (as shown in the attachment), but it didn't work very well. I would appreciate it if you could help me to point out the problem.

    I hope you can help me solve this problem. thank you very much. And I'm really sorry for the trouble caused by the language problem.

    Best wishes


  • Dear Danna,

    thank you for your request.

    Please find attached a VisualApplets design in which following processing is implemented:

    Input a gray: pixel I (I, J),

    If I(I,J)<64,: r = 0, g = 4 * I (I, J), B = 255;

    If 63 < I(I,J)< 128: r = 0, g = 255, B = 255-4 * [I (I, J) - 64]

    If 127< I(I,J)<192: r = 4 * [I (I, J) - 128], G= 255, B = 0

    If 191< I(I,J): r = 255, g = 255-4 * [I (I, J) - 192], B = 0

    The only difference to the color processing you have described is for the case 63 < I(I,J)< 128. In order to be sure to have 8 bit value (less than 255), the value 128 was substituted by 64.

    I hope this design is helpful for you.

  • Dear Carmen Z,

    The decimal part is often removed when using the DIV operator for division operations, but the image processing I want to perform will cause large errors when removing the decimal part. Is there any way to add the removed decimal part to the calculation process?

    For example, the division operation has been performed to get the integer part A and the decimal part B. Next, I need to perform square processing. How can I get (A + B). ^ 2?

    I wrote a VA file (as shown in the attachment), and hope you can help me solve this problem.Thank you very much!

    Best wishes




      (7.41 kB, downloaded 1 times, last: )
  • Dear Carmen Z,

    When I generate the HAP file from the program (as shown in the attachment), there is a problem--time requirement not meet. Can you help me modify the program correctly? Or point out the problem?

    Thank you very much!

    Best wishes


  • Dear Danna,

    thank you for your questions.

    1. Concerning you question from Februray 23rd:

    Please find attached the design "" : In this design an example for the calculation with so called fractional bits is implemented:

    For the calculation in VisualApplets you can only use Integer values. When you want to perform division or other mathemetical operations with values smaller than 1 you can use a "trick":

    For example input pixel value I=2:

    -Division by 20: 2/20= 0.1

    -Problem: Only integer values can be processed

    -Solution: Mulitply input by 2^x: x e.g. =10: We call this fractional bits

    -2*(2^10)/20= 102,4 => Value 102 (with 10 fractional bits) is result from division operation

    -102 corresponds to 102/2^10, which is ~0.1

    The more fractional bits you use the more accurate the result from division operation is.

    2. Concerning your request from March 3rd:Build problems of hap file:

    The design clock is set to 312 Mhz in design "". This is causing the timing error.

    Please reduce the design clock frequency to 125 MHz.

  • Dear Carmen Z,

    I generated the HAP file through the VA program, and then burned it to the acquisition card (me5-ma-vcl), but no image appeared. The camera used is ACA 2040-180km of basler, and the camera is set to 1 × 8-1Y (tap geometry) and Full mode (configuration) through the camera software pylon.

    In addition, how can I modify camport? My VA software has set two DMA outputs, but their ports are all displayed as port A. does this cause image display failure?


    Thank you very much!

    Best wishes


  • Dear Danna,

    In case a single camera feeds two DMA ports both have to be started.

    A possible side effect in microDisplay may cause this behaviour.

    Please have a look here to make a correspnding setting.

    I would recommend to use microDisplayX (newer version), where you can select the start synchronization in the top menu.

    Since the loop of the VA design may cause a deadlock or asynchronous behaviour, please run a simulation with a sequence of images. By this you can see the possible side effects and maybe find the root-cause already in the simulation before synthesis.

    I do not have the corresponding hardware to double-check the HAP in runtime.

    If it is possible you can provide the related VA-Design together with the intended image-sequence. Then I can have a look into the simulation and maybe adopt some necessary changes.

    Thank you.

  • Dear B.Ru,

    I've changed the settings as shown in the link, but I still can't solve the problem. The attachment is my VA program and corresponding image. In addition, can you send me the microdisplay x installation package?


    Thank you.

  • Hi Danna,

    I looked into your VA design and found two possible reasons for the deadlock.

    One was an unnecessary SYNC for merging the Average stream.

    The second reason for not getting useful data was the CL BASE operator in the Process, while you wanted to run a CL FULL configuration on the camera.

    So I changed the Camera operator for you:

    The simulation looks plausible now:


    Please be aware that the paralleism of the CL FULL camera operator is higher than the bandwidth your design can handle. That may cause a backlog in the initial/first RAM operator in the que.

  • Dear B.Ru,

    I have generated the HAP file according to the modified VA software, but it is still unsuccessful. The attachment is a log file. Please look at it and help me to confirm the problem.

    Thank you.

  • Hi Danna,

    Based on the log, the software is accessing:

    #define FG_CAMSTATUS_EXTENDED 2050

    returns the status information of a particular camera link chip: Bits [0] Clock, [1] LVAL, [2] FVAL, [3] ExSync, [4] ExTrg, [5] Overflow, [6:7] BufLvl

    on the second DMA. That is a parameter ID existing for dual acquisition applets.

    To me it is unclear if it exists for VA Applets, too. Especially since you have 2 DMAs and a single camera.

    Please check in your design if the following setup of the camera is correct:


    When I see it correctly then this camera operator is setup for CL DECA 10tap 8 bit, while in this thread you mentioned above requiring: CL FULL 8tap at 8bit. You can change FullMmode during runtime, so no resynthesis is required.