Главная страница


ru.algorithms

 
 - RU.ALGORITHMS ----------------------------------------------------------------
 From : Alex Baskakov                        2:5025/3.55    26 May 2002  00:32:36
 To : Alex Astafiev
 Subject : RGB 16M -> B/W 256
 -------------------------------------------------------------------------------- 
 
 
 24 Май 02 16:44, Alex Astafiev -> Max Vikulov:
 
  MV>>  Господа, подскажите, как из RGB TrueColor перевести изображение в
  MV>>  режим "256 оттенков серого" ?
  AA> Dest := Byte(Longint(Word(R) * 77 + Word(G) * 150 + Word(B) * 29) shr 8);
 
 Есть много способов.
 
 =============================================================================
 * Area : CODE.ZX (CODE.ZX)
 * From : Dmitry Grigoryev, 2:5020/689.31@FidoNet (Воскp 28 Февpаля 1999 11:34)
 * To   : Arseniy Astapenko
 * Subj : bmp-screen
 =============================================================================
 Привет, Arseniy!
 
 Втоpник 16 Февpаля 1999 23:43, Arseniy Astapenko (500:17/1@ZXNet) wrote to All:
  AA>      Hello All!
  AA> B,G,R,Reserved. Кто точно может сказать как
  AA> правильно упрорядочить цвета и перевести сабж в
  AA> градации серого?
 
 PaintShop Pro конвертит так:
 0.298*R+0.588*G+0.110*B
 
 О! Крутой документик нашел:
 
 ННННННННННµImportBegin COLOR_~1.TXTЖНННННННННННННННННННННННННННННННН
 Color spaces FAQ - David Bourgin ~Date: 18/4/95 Last update: 3/4/95
 
 [пропущено...]
 
 9 - Color quantizations
 An important problem in color processing comes up with your
 displaying/printing device. In fact, many output devices can't reproduce all
 the colors you want. In many cases you must convert all your colors into a
 subset. We will see from now some references or algorithms to deal with that
 problem.
 
 9.1 - Full color space to color look-up table
 Usually, you will need to quantize 24-bit color images downto 8-bit color
 images. (The conversions into grayscale or bi-level images are explained in
 the next section.) There are several means to do so. I suggest you read the
 references given in comp.graphics FAQ stored on rtfm.mit.edu:
 /pub/usenet/news.answers/graphics/faq maintened by John T. Grieggs
 (grieggs@netcom.com).
 
 9.2 - Color look-up table to a gray scales
 
 It is really easy to convert a picture into its grayscale representation. To
 do so, you take your RGB picture (if you don't have a RGB picture, have a look
 into section 8 and subsections) and you translate each RGB value into the
 luminancy value.
 Old softwares used Rec 601-1 and produced:
 Gray scale = Y = (299*Red+587*Green+114*Blue)/1000
 With Rec 709, we have:
 Gray scale = Y = (213*Red+715*Green+72*Blue)/1000
 Some others do as if:
 Gray scale = Green (They don't consider the red and blue components at all)
 Or, alternativly, you can average the three color components so:
 Gray scale = (Red+Green+Blue)/3 But now all people *should* use the most
 accurate, it means ITU standard:
 Gray scale = Y = (222*Red+707*Green+71*Blue)/1000
 (That is very close to Rec 709!) I performed some personal tests and have
 sorted them in regard with the global resulting luminancy of the picture (from
 my eye point of view!). The following summary gives what I found ordered
 increasingly:
 
     +---------------------------------+-----------------+
     | Scheme                          | Luminancy level |
     +---------------------------------+-----------------+
     | Gray = Green                    |        1        |
     | Gray = ITU (D65)                |        2        |
     | Gray = Rec 709 (D65)            |        3        |
     | Gray = Rec 601-1 (C illuminant) |        4        |
     | Gray = (Red+Green+Blue)/3       |        5        |
     +---------------------------------+-----------------+
 So softwares with Gray=Rec 709 (D65) produce a more dark picture than with
 Gray=Green. Even if you theorically lose many details with Gray=Green scheme,
 in fact, and with the 64-gray levels of a VGA card of a PC it is hard to
 distinguish the loss.
 
 9.3 - Gray scales to black and white
 
 Usually, you need to convert a color picture into black and white for printer
 output device. To do so, you must do it into two steps. The first step is to
 convert your color picture into a gray level picture, as explained in section
 9.2. In the second step you have to convert your grey level picture into a
 black and white picture. This second stage can be done by several ways
 depending on your output device. All the ways are based on the fact that human
 eye is unable to distinguish small displayed/printed informations. So, if two
 points are very close to each other, they are mixed to a single point. Of
 course, there is a limit from which your eye will be able to see a pattern.
 That is why your output device must be as precise as possible.
 
 The first way to produce monochrome pictures is the halftoning scheme. In this
 scheme, a point is output as big as the input gray level is dark, and, at the
 opposite, a point is output as small as the input gray level is light. The
 size of the output point can be produced by using more or less ink or by
 writting several dots closely in an aggregate but unable to distinguish as a
 pattern by the eye. The rules to make aggregates are given as follows:
  * Two aggregates of two successive gray scales must differ by adding/removing
 one dot. A nxn matrix of dots produce n^2+1 different gray levels.
  * Two aggregates placed side by side must not appear as a pattern.
  * The aggregate must be built by addding step by step dots from the center of
 the aggregate.
 For example, a 2x2 aggregate is (D means a black dot to place):
 
        +-+-+         +-+-+         +-+-+         +-+-+         +-+-+
        | | |         |D| |         |D| |         |D|D|         |D|D|
        +-+-+         +-+-+         +-+-+         +-+-+         +-+-+
        | | |         | | |         | |D|         | |D|         |D|D|
        +-+-+         +-+-+         +-+-+         +-+-+         +-+-+
     Aggregate 1   Aggregate 2   Aggregate 3   Aggregate 4   Aggregate 5
 You can express it as the following matrix:
 
          | 0 2 |
     M  = | 3 1 |
      2
 Note that the numbers in M2 are such that first dot is placed at the top left
 hand corner (value 0), the second dot is placed at the bottom right hand
 corner (value 1), and so on.
 
 You can generalize that by the following algorithm (which produces Mn such
 that n=2^k):
 
     Mn[0;0] <- 0
     Mn[0;1] <- 2
     Mn[1;0] <- 3
     Mn[1;1] <- 1
     for I <- 2 to k
     do J <- 1 binary_shift_left (I-1)
        for X <- 0 to J-1
        do for Y <- 0 to J-1
           do Mn[Y;X] <- Mn[Y;X] binary_shift_left 2
              Mn[Y;X+J] <- Mn[Y;X]+2
              Mn[Y+J;X] <- Mn[Y;X]+3
              Mn[Y+J;X+J] <- Mn[Y;X]+1
           end loop
        end loop
     end loop
 Halftoning is good with high definition output device as laser printer but it
 is hard to apply for displaying or in graphics files because each point is
 output as a set of dots => You enlarge the bitmapped picture!
 
 After halftoning, we can consider thresholding schemes. In these schemes, you
 take a single value or a set of values and each gray level is compared to the
 threshold value(s). If the gray level is lesser than the threshold then you
 output a black dot otherwise you output white.
 
     for X <- 0 to Image_Size_in_X-1
     do for Y <- 0 to Image_Size_in_Y-1
        do if Read_Gray_Level(X,Y)<128
           then Write_Dot(X,Y,Black)
           else Write_Dot(X,Y,White)
           end if
        end loop
     end loop
 I assume that Read_Gray_Level function gives a gray level within the range 0
 to 255.
 
 We can generalize the single threshold by using a set of thresholds, as
 defined in Bayer's scheme. In this scheme we take the Mn matrices we saw
 previously. For examples, with a 4-bit gray level picture you use M2 and with
 an 8-bit gray level picture we use M16 (n=16, and k=4):
 
     for X <- 0 to Image_Size_in_X-1
     do for Y <- 0 to Image_Size_in_Y-1
        do if Read_Gray_Level(X,Y)<M16[X logical_binary_and 15;Y
 logical_binary_and 15]
           then Write_Dot(X,Y,Black)
           else Write_Dot(X,Y,White)
           end if
        end loop
     end loop
 Note that the "logical binary and" operation is made to avoid X and Y value to
 be beyond the range [0;15]. This is equivalent to a modulo 16 operation, but
 faster on computers.
 
 Thresholding schemes are simple and produce quick good results but they can be
 replaced by the very good schemes called dithering. The principle of dithering
 is simple. We re-adjust the error made on a dot in output by diffusing the
 error to the neighbouring dots. That's why we also call this scheme error
 diffusion. For example, let's consider X as the analysed point. The
 neighbouring points are re-adjusted by the following coefficients presented in
 the following matrix.
 
     +-+-+-+
     | |X|7|
     +-+-+-+
     |3|5|1|
     +-+-+-+
 around X, only four points are adjusted with the error. The sum of the
 adjustment is 7+3+5+1=16. For example, the pixel to the right of X is adjusted
 by 7/16 of the error made on X (the error can be positive as well negative!).
 This filter is very popular because it is the Floyd-Steinberg's filter. To
 have more information about that, have a look in ULICHNEY (see section 11).
 The problem of halftoning is that you need input gray levels as well readable
 as writeable. The process can be slow but it produces nicest results compared
 to fast thresholding scheme.
 
 ННННННННННµImportEnd COLOR_~1.TXTЖНННННННННННННННННННННННННННННННН
 
  AA>             Ars^FTL
 
 С уважением, Дмитрий (OLDMAN).             500:095/100.1@ZXNet
                                            oldman@i-connect.ru
 
 -+- GoldED/386 3.0.0-dam9
  + Origin: ... (2:5020/689.31)
 =============================================================================
                                                                    Пр. ещё, Л.
 --- G\/R ---
  * Origin: It's a new morning in America! (2:5025/3.55)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 RGB 16M -> B/W 256   Max Vikulov   23 May 2002 23:18:08 
 RGB 16M -> B/W 256   Alex Astafiev   24 May 2002 16:44:12 
 RGB 16M -> B/W 256   Alex Baskakov   26 May 2002 00:32:36 
Архивное /ru.algorithms/27873cf02f58.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional