LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

run length encoding (horizontal and vertical) of an bitmap image

Good day to all.

 

Recently I have working on some image processing related to shortest path algorithm. I have came across "run length encoding"As it is not to understand the concept but I am have no idea, how to implement it in LabVIEW. My test images are in binary (0 and 1). and I am trying to get horizontal and vertical run length encoding of test images. I am looking for some suggestions and help regarding where and how to start.

 

For reference to run length encoding here is a link . 

 

Thank you for any suggestions. 

0 Kudos
Message 1 of 8
(5,116 Views)

Hi kumar,

 

but I am have no idea, how to implement it in LabVIEW

You have put that link in your post!

Why don't you follow the scheme/algorithm presented in this linked document? It's all you will need…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(5,075 Views)

@kumar1993 wrote:

have working on some image processing related to shortest path algorithm. I have came across "run length encoding"As it is not to understand the concept but I am have no idea, how to implement it in LabVIEW. My test images are in binary (0 and 1). and I am trying to get horizontal and vertical run length encoding of test images. I am looking for some suggestions and help regarding where and how to start.

 


RLE is typically used for compression, not for analysis. Since the output is compressed, it seems much more difficult to analyze it (e.g. for shortest path and such). Can you explain your reasoning behind your approach?

Message 3 of 8
(5,060 Views)
I wanted to use RLE to get most common pattern of Black pixels horizontally and vertically. That way, I could use that as a threshold to determine the pixels height for shortest path approach. Any path bigger than that height should be rejected. That's my thinking but I am open to other ideas. Thank you.
0 Kudos
Message 4 of 8
(5,041 Views)

Ok, I have happen to figure this problem out. Thank you for all your help. 

I felt I should be sharing this file for anyone else who could be interested in "Run-Length Encoding."

 

In this code, input image format is .BMP. There is a preprocess before the run length counting, in which you have to choose a threshold to convert image to binary. (so, Basically, it only works in grayscale domain.) 

there is an output array as final result every odd index is number of balck pixels and every even is number of white pixels. This  calculates run length vertically and horizontally.

0 Kudos
Message 5 of 8
(4,972 Views)

There are many places for improvement in efficiency and code readability. For example:

 

  • One of your  "select" nodes in the first loop could be replaced by a boolean "Not", or nothing if you would use the opposite comparison (less than) :D. (See also).
  • If you are dealing with greyscal images, all you need to compare is R, G, or B, because they are all equal. No need to average. (See image)
  • In the upper right loop, you can autoindex on the 2D array. Same for the lower loop if you transpose.
  • "built array" is a better choice to append than "insert into array" with the index disconnected.
  • You have way too many coercion dots. Choose the right representation for controsl and diagram constants.
  • You can eliminate the zeroes inside the case structures by setting the output tunnel to use default if unwired.
  • Your two right loop pyramids are virtually identical (except for the tranpose of the array input). So turn it into a subVI and re-use the code. (If you want them to still run in parallel, inline the subVI).
  • You could use a single loop for the RLE by reshaping the 2D array into a 1D array.
  • You don't even need the U8 array, the RLE code could work equally well on the boolean array (after some small adjustments).

... just some ideas. There are many more 😉

 

Message 6 of 8
(4,957 Views)
Thank you so much your help. I would try to follow your steps and improve it.
0 Kudos
Message 7 of 8
(4,941 Views)

Hey Kumar,

I was trying to implement simple run-length coding in LabVIEW as per my college project. The algorithm should simply contain an input stream and the output in the form of RLE, no images or anything but simply a bitstream. But, I don't know how to do it, can you help?  

0 Kudos
Message 8 of 8
(3,171 Views)