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.