5. Create directory is linear
offset = 0;
for (line = 0; line < hight; line++)
{
{
length = 0;
while (length < width)
{
length += run.getLength();
run.next();
offset++;
}
output(offset);
}
}
6. The Geometric Operations
OP Procedure
No op Copy source to destination row by row run by run.
Column flip Read input columns in reverse order.
Row flip Read input rows in reverse order.
Rotate 180° Do row flip and column flip.
Diagonal flip Swap rows with columns.
Rotate 90° (CCW) Do column flip and then diagonal flip.
Rotate 270° (CW) Do row flip and then diagonal flip.
Opposite diagonal flip Do 180° rotation and diagonal flip.
Rotate by 0° < α ≤ 45°
Rotate by 0° > α ≥ 45°
Rotate by any angle
8. The Columns flip operation.
• for (line = 0; line < height; i++)
• {
• start = directory[line];
• ends = directory[line + 1];
• // go backwards
• for (index = ends – 1; index >= start; index--)
• {
• output_run(image[index]);
• }
• }
9. The Rows flip operation.
• for (line = 0; line < height; line++)
• {
• start = directory[height - line - 1];
• ends = directory[height - line];
• // go forwards
• for (index = start; index < end; index++)
• {
• output_run(image[index]);
• }
• }
10. The Rotation by 180°
operation.
• for (line = 0; line < height; line++)
• {
• start = directory[height - line - 1];
• ends = directory[height - line];
• // go backwards
• for (index = ends – 1; index >= start; index--)
• {
• output_run(image[index]);
• }
• }
11. The Diagonal Flip operation.
• Merging process
• For each line sequence runi={leni,colouri}
• Create ordered list {Σi
j=0 lenj,colouri}
• Use regular merging algorithm
• Compare colours while merging.
The 1 st the 2 nd and 3 rd cases are when two runs have the same colour. In all of these cases we know that no output run should be created, at least in the overlapping region, and this overlapping region ends at the minimum of the two runs. Therefore what is needed to do is just to record this minimum column. These three cases are described in figures one to three below.
The 4th the 5 th and 6 th cases are when two runs don’t have the same colour. Now if two runs from two successive lines have an overlapping span then it is obvious that a run in the flipped image terminate and new runs start as can seen form the next pictures. Output run should be created from the last recorded column of unmatched colour up to the minimum of the runs. The column of the minimum run is recorded as it was recorded in the previous cases.
Now when an output run is to be created there are two things that are needed, the colour and the length. The colour of the run is just the colour of the top run. The length of the run is the difference between the line index of the bottom line and the index of the line where this line started. Now all what is needed is to remember on which line this run started, it started of course when a run above it terminated, or at the top of the image. In order to "remember" where each run started, the algorithm will use an auxiliary array called start that keeps track on the starting line of output runs that are not yet written. To clarify it lets look at a bit mapped grid virtually laid over the run length encoded image together with the auxiliary start array at the top row. And assume that the lines that are merged are lines 3 and 4. Then the situation will be like the following
Destination pixel at (1:7) does not have any source, No source pixel is mapped to (1:7) Destination pixel at (0:7) has two sources. In reverse trans pixel (1:7) will not be sampled and pixel (0:7) will be sampled twice. It is not reversible.
Perform rotation by three successive sheering transformation.
Vertical sheering is not efficient in bit mapped image because of memory architecture. It is also not natural for run length encoded images. Can do vertical sheering by transposing and horizontal sheering.
Assume one wish to rotate by a small angle an image that consists of horizontal stripes that alternate their colours each line. The output image is likely to have the same order of the input image, but the intermediate images after the 90° rotation will have a very big size, since it is an image of vertical stripes, and this kind of image does not compress well with run length encoding.
The 1 st case is when the two runs ends after a breaking line but before the next breaking line, and the top run ends after the bottom run, as the next picture shows. In this case no output run ends, and the merge process continues.
In the 2 nd case is when to top run ends before or together with the bottom line, but not at a breaking line. I this case an output run is created
In 3 rd case the bottom run ends exactly at a breaking line, while the top run continues. Now since a run ends only when the colour changes, we know that a top run must ends, and a run should be created.
In the 4 th case the top run ends after the breaking line while the bottom run ends before the breaking line. In this case it is possible that the top run colour will return and the previous colour will be restored and the top run will continue. Therefore we don’t create a run yet.
The 5 th is when the top and bottom run ends exactly at a breaking line, case is similar two the 3 rd case, and as result an output run should be created.
In the 6 th is similar to the 4 th and the same reasoning apply.
In the 7 th case the top run ends at a breaking line but the bottom run continues. In this case no output run is created and the merge process continues.
In the 1 st case we need to create a run at each breaking line, the fate of the last segment is still unknown.
In the 2 nd case when the bottom run ends at a breaking line leaves us with another unclosed run since the bottom line change colour, and it is possible that it will change colour two the top line colour.
The 3 rd case is just like the 2 nd as we still don’t know how the segment will end.
The 4 th case is the same.
The 5 th case ditto.
Cohen algorithm for digital image rotation is a source to destination algorithm. As it takes each of the original image pixels and put it in the destination image. One can look at this algorithm as taking imaginary lines that passes trough the centre of the pixels of the top horizontal line and the centre of the pixels of the left vertical line, rotate these lines and the use Bresenham algorithm in order to create parallel filling pattern, as shown in the next picture.
The Cohen algorithm can be described by the next equation. Where for small θ the multiplication result approximate a rotation matrix. And therefore Cohen's algorithm is suitable for small angles only, where it has a marginal speed advantage.
From this equation one learn that there is a need to scale down each line by a factor of the sinus of rotation angle and to scale up the vertical dimension of the image by a factor of the secant of the rotation angle. Scaling up an image in the vertical dimension can be done by replicating some of the input lines, while scaling down a line can be done by deleting pixels from lines. In order to delete pixels from input line in linear time an auxiliary array "outcol" that maps each input column to output columns will be used. Both the scale up and the calculation of the "octcol" array can be done using Bresenham, DDA or any other algorithm of choice. The modified algorithm scales correctly the input image and does it in linear time, but it is irreversible. The irreversibility is a direct consequence of the scale down operation that might cause small runs to disappear.