Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. An Algorithm !!

An Algorithm !!

Scheduled Pinned Locked Moved Managed C++/CLI
algorithmstutorialquestionlearning
21 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V VaporTrace

    Wouldn't it be easier to bitmap it then recompress it back into the jpeg using the same algorithm format?

    V Offline
    V Offline
    VaporTrace
    wrote on last edited by
    #4

    Wait a minute it just dawned on me what you are doing. You are creating reference for jpeg compression algorithm which means you are working in bitmap already.

    1 Reply Last reply
    0
    • C Christian Graus

      Jomy John wrote: Can someone tell me ....what kind of algorithm i could use ...to calculate the pixel intensity values ..ie their color ?? Do you mean group by color ? Then you just well, group by color. Otherwise, perhaps you want to convert to the HLS color space, and group by saturation, luminance, or hue ? Christian Graus - Microsoft MVP - C++

      J Offline
      J Offline
      Jomy John
      wrote on last edited by
      #5

      actually hoinestly i dunno .... What i am told to do is ... Group information similar to pixels ...and send them in this format as text ...as in SMS .... So , most probably it would be color .... Please help Thanks , Jomy

      C 1 Reply Last reply
      0
      • J Jomy John

        actually hoinestly i dunno .... What i am told to do is ... Group information similar to pixels ...and send them in this format as text ...as in SMS .... So , most probably it would be color .... Please help Thanks , Jomy

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #6

        You can get the colour values of a bitmap by using a DIBSection to hold it, or by using GDI+ ( which comes with VC7, is in the PSDK for VC6 ). Or you can use the GetPixel function on the DC, but that's really slow. Also, if you don't use a DIBSection or just a DIB, you won't get an accurate color value range for your image, unless your computer is running in 24 bit mode. So you want to turn an image into text, so it can be sent as ASCII art ? There's at least one article on doing this on this site, do a search for it and your problems may be solved. Christian Graus - Microsoft MVP - C++

        J 1 Reply Last reply
        0
        • C Christian Graus

          You can get the colour values of a bitmap by using a DIBSection to hold it, or by using GDI+ ( which comes with VC7, is in the PSDK for VC6 ). Or you can use the GetPixel function on the DC, but that's really slow. Also, if you don't use a DIBSection or just a DIB, you won't get an accurate color value range for your image, unless your computer is running in 24 bit mode. So you want to turn an image into text, so it can be sent as ASCII art ? There's at least one article on doing this on this site, do a search for it and your problems may be solved. Christian Graus - Microsoft MVP - C++

          J Offline
          J Offline
          Jomy John
          wrote on last edited by
          #7

          Im not supposed to use VC ....plain C++ ... Im thought of using the getpixel() function but ...its returning me ..integer values ...actually am not sure ..whether im thinking in the right pattern or not ... And would ASCII art fit into the SMS character set ?? Only then i would be able to use it ... Please guide .... Thanks Jomy

          C 1 Reply Last reply
          0
          • J Jomy John

            Im not supposed to use VC ....plain C++ ... Im thought of using the getpixel() function but ...its returning me ..integer values ...actually am not sure ..whether im thinking in the right pattern or not ... And would ASCII art fit into the SMS character set ?? Only then i would be able to use it ... Please guide .... Thanks Jomy

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #8

            Jomy John wrote: Im not supposed to use VC ....plain C++ ... Well, if you're using bitmaps in Windows, then you need to use Windows bitmap structures. Jomy John wrote: Im thought of using the getpixel() function but ...its returning me ..integer values Use GetRValue, GetGValue and GetBValue macros to get the colours out of that COLORREF. Jomy John wrote: And would ASCII art fit into the SMS character set ?? Only then i would be able to use it ... ASCII art uses any characters you like, AFAIK. Christian Graus - Microsoft MVP - C++

            J 1 Reply Last reply
            0
            • J Jomy John

              Hey all ..... Can someone tell me ....what kind of algorithm i could use ...to calculate the pixel intensity values ..ie their color ?? I have a image processing book by Gonsalez ...but cant find exactly what i need .... Im supposed to find the pixel intensities of all the pixels in a Jpeg file ...and group all the pixels having the same values ... Please guide me .... Thanks , Jomy

              J Offline
              J Offline
              Johann Gerell
              wrote on last edited by
              #9

              Assuming that the JPEG is decoded and that you have a raw RGB888 (24 bpp) DWORD-aligned stream:

              1. Get a pointer to the first DWORD, pPixel.
              2. Assign the color componenent values of that pixel to a COLORREEF, color = *pPixel.
              3. Multiply the RGB components to get the intensity (assuming that is the intensity definition...), intensity = GetRValue(color) * GetGValue(color) * GetBValue(color).
              4. Store the pixel id and its intensity somehow (defined by you), StorePixelIntensity(id, intensity).
              5. Continue to the next pixel, ++pPixel.
              6. Goto 1 if there are more pixels.

              -- The Blog: Bits and Pieces -- modified at 2:05 Wednesday 21st September, 2005

              J 1 Reply Last reply
              0
              • J Johann Gerell

                Assuming that the JPEG is decoded and that you have a raw RGB888 (24 bpp) DWORD-aligned stream:

                1. Get a pointer to the first DWORD, pPixel.
                2. Assign the color componenent values of that pixel to a COLORREEF, color = *pPixel.
                3. Multiply the RGB components to get the intensity (assuming that is the intensity definition...), intensity = GetRValue(color) * GetGValue(color) * GetBValue(color).
                4. Store the pixel id and its intensity somehow (defined by you), StorePixelIntensity(id, intensity).
                5. Continue to the next pixel, ++pPixel.
                6. Goto 1 if there are more pixels.

                -- The Blog: Bits and Pieces -- modified at 2:05 Wednesday 21st September, 2005

                J Offline
                J Offline
                Jomy John
                wrote on last edited by
                #10

                i have to code purely in C++ ...!!! newes ..using Sir Johann 's method is gud..assuming thats the right defn of intensity .... Anuther thing one of my friends suggested ..was to convert to gray scale ..and check for similar intensity ... Will that be rite ? And all i have with me in C++ , for RGB color extraction is getpixel() ...how do i process my Jpeg file using getpixel as its just returning me single integer values .... That is ... int c = getpixel(0,0) cout << c ; gives me not the typical 32 bit value ...but a single 0 and a series of sets of 0's and 7's when tried for the entire file ! How should i continue ? Thanks Jomy

                1 Reply Last reply
                0
                • C Christian Graus

                  Jomy John wrote: Im not supposed to use VC ....plain C++ ... Well, if you're using bitmaps in Windows, then you need to use Windows bitmap structures. Jomy John wrote: Im thought of using the getpixel() function but ...its returning me ..integer values Use GetRValue, GetGValue and GetBValue macros to get the colours out of that COLORREF. Jomy John wrote: And would ASCII art fit into the SMS character set ?? Only then i would be able to use it ... ASCII art uses any characters you like, AFAIK. Christian Graus - Microsoft MVP - C++

                  J Offline
                  J Offline
                  Jomy John
                  wrote on last edited by
                  #11

                  Honestly ...i did not understand anything of what uve said ... Can you please explain in detail ...if its not a botheration .. as in GetRValue , GetBValue ..etc are functions in C++ or VC++ ?? Help !! Sorry for the trouble ..... Thanks, Jomy

                  C 1 Reply Last reply
                  0
                  • J Jomy John

                    Honestly ...i did not understand anything of what uve said ... Can you please explain in detail ...if its not a botheration .. as in GetRValue , GetBValue ..etc are functions in C++ or VC++ ?? Help !! Sorry for the trouble ..... Thanks, Jomy

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #12

                    Jomy John wrote: as in GetRValue , GetBValue ..etc are functions in C++ or VC++ ?? The obvious thing would have been to type them into the IDE and see what happened. A COLORREF is just a DWORD, and the GetXValue macros just use byte shifting to pull out the single color. If you wanted to deal with colors as a unit, rather than the pixel values, you may as well sort/group on the colorref, but if you want to work out what the colors are, you need to pull them out in this way. In all cases, they are specific to Windows, and probably to VC. Christian Graus - Microsoft MVP - C++

                    J 1 Reply Last reply
                    0
                    • C Christian Graus

                      Jomy John wrote: as in GetRValue , GetBValue ..etc are functions in C++ or VC++ ?? The obvious thing would have been to type them into the IDE and see what happened. A COLORREF is just a DWORD, and the GetXValue macros just use byte shifting to pull out the single color. If you wanted to deal with colors as a unit, rather than the pixel values, you may as well sort/group on the colorref, but if you want to work out what the colors are, you need to pull them out in this way. In all cases, they are specific to Windows, and probably to VC. Christian Graus - Microsoft MVP - C++

                      J Offline
                      J Offline
                      Jomy John
                      wrote on last edited by
                      #13

                      Anyways its not suiting my purpose...i just cant use VC!! My project guide in college wants me to compulsorily use ..plain ol C++ !!! Also , in a Jpeg file ...where do i get the pixel related color information ...as in I scanned the Jpeg file format ...but I cant find a specific offset from where actual pixel information starts .... jpeg is just clustered as headers ..... Please tell me Thanks , Jomy

                      C 1 Reply Last reply
                      0
                      • J Jomy John

                        Anyways its not suiting my purpose...i just cant use VC!! My project guide in college wants me to compulsorily use ..plain ol C++ !!! Also , in a Jpeg file ...where do i get the pixel related color information ...as in I scanned the Jpeg file format ...but I cant find a specific offset from where actual pixel information starts .... jpeg is just clustered as headers ..... Please tell me Thanks , Jomy

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #14

                        Jomy John wrote: My project guide in college wants me to compulsorily use ..plain ol C++ !!! Bloody hell. Your guide is an idiot. 'plain old C++' knows nothing about images, let alone colours. Jomy John wrote: Also , in a Jpeg file ...where do i get the pixel related color information ...as in I scanned the Jpeg file format ...but I cant find a specific offset from where actual pixel information starts .... Nope, it doesn't work that way. A jpeg is compressed, which means you need to use a library, which means you won't be using 'plain old c++' Christian Graus - Microsoft MVP - C++

                        J 1 Reply Last reply
                        0
                        • C Christian Graus

                          Jomy John wrote: My project guide in college wants me to compulsorily use ..plain ol C++ !!! Bloody hell. Your guide is an idiot. 'plain old C++' knows nothing about images, let alone colours. Jomy John wrote: Also , in a Jpeg file ...where do i get the pixel related color information ...as in I scanned the Jpeg file format ...but I cant find a specific offset from where actual pixel information starts .... Nope, it doesn't work that way. A jpeg is compressed, which means you need to use a library, which means you won't be using 'plain old c++' Christian Graus - Microsoft MVP - C++

                          J Offline
                          J Offline
                          Jomy John
                          wrote on last edited by
                          #15

                          How i wish i could tell him that !! But i have to ....sadly ...for making life hell for me :( Is there like no solution for this problem ?? Although im not sure ..but mebbe hez asking me to do it using C++ , bcos eventually when i want to send my file as an SMS , i have Symbian as my OS ...and mebbe it supports only that compiler ...!!! Anyways , as Jpeg is compressed , like you said .... How would i then read the RGB / YCbCr values ?? Please help me wid this !!! A totally frustrated jomy

                          C 1 Reply Last reply
                          0
                          • J Jomy John

                            How i wish i could tell him that !! But i have to ....sadly ...for making life hell for me :( Is there like no solution for this problem ?? Although im not sure ..but mebbe hez asking me to do it using C++ , bcos eventually when i want to send my file as an SMS , i have Symbian as my OS ...and mebbe it supports only that compiler ...!!! Anyways , as Jpeg is compressed , like you said .... How would i then read the RGB / YCbCr values ?? Please help me wid this !!! A totally frustrated jomy

                            C Offline
                            C Offline
                            Christian Graus
                            wrote on last edited by
                            #16

                            Jomy John wrote: Is there like no solution for this problem ?? The solution is that your code needs to take an array of color values, and not a bitmap of any sort. Because all bitmap formats fall outside the bounds of 'standard C++'. Jomy John wrote: Anyways , as Jpeg is compressed , like you said .... How would i then read the RGB / YCbCr values ?? Ya just can't. If you're not allowed to use GDI+, I don't see how you could be allowed to use any other library for reading jpegs. I'm sure your teacher knows this, and that you're completely misunderstanding the task at hand. Paintlib is one cross platform library that will let you read jpegs and get the pixel values. Christian Graus - Microsoft MVP - C++

                            J 1 Reply Last reply
                            0
                            • C Christian Graus

                              Jomy John wrote: Is there like no solution for this problem ?? The solution is that your code needs to take an array of color values, and not a bitmap of any sort. Because all bitmap formats fall outside the bounds of 'standard C++'. Jomy John wrote: Anyways , as Jpeg is compressed , like you said .... How would i then read the RGB / YCbCr values ?? Ya just can't. If you're not allowed to use GDI+, I don't see how you could be allowed to use any other library for reading jpegs. I'm sure your teacher knows this, and that you're completely misunderstanding the task at hand. Paintlib is one cross platform library that will let you read jpegs and get the pixel values. Christian Graus - Microsoft MVP - C++

                              J Offline
                              J Offline
                              Jomy John
                              wrote on last edited by
                              #17

                              Ok...heights now my giude tells me that my way was totally wrong ... :( He wants me to learn algorithms ...that will are general to all iamges ... !! ie how an image will be stored on the hdd..it seems there is an algo for that ..that applies to all types of images Does neone have a knowledge abt this ?? Sorry ...abt the confusion created in the above posts .. Thanks , Jomy

                              C 1 Reply Last reply
                              0
                              • J Jomy John

                                Ok...heights now my giude tells me that my way was totally wrong ... :( He wants me to learn algorithms ...that will are general to all iamges ... !! ie how an image will be stored on the hdd..it seems there is an algo for that ..that applies to all types of images Does neone have a knowledge abt this ?? Sorry ...abt the confusion created in the above posts .. Thanks , Jomy

                                C Offline
                                C Offline
                                Christian Graus
                                wrote on last edited by
                                #18

                                Jomy John wrote: ie how an image will be stored on the hdd..it seems there is an algo for that ..that applies to all types of images Sorry, but you MUST still be confused. How an image is stored depends on the format, and is common to all image types only in that, at the end of the day, it's all a bunch of 1s and 0s. There's a variety of compression algorithms used in image formats, but no common one. BMP is one that is not compressed at all. Christian Graus - Microsoft MVP - C++

                                J 1 Reply Last reply
                                0
                                • C Christian Graus

                                  Jomy John wrote: ie how an image will be stored on the hdd..it seems there is an algo for that ..that applies to all types of images Sorry, but you MUST still be confused. How an image is stored depends on the format, and is common to all image types only in that, at the end of the day, it's all a bunch of 1s and 0s. There's a variety of compression algorithms used in image formats, but no common one. BMP is one that is not compressed at all. Christian Graus - Microsoft MVP - C++

                                  J Offline
                                  J Offline
                                  Jomy John
                                  wrote on last edited by
                                  #19

                                  No..im just quoting the stuff my project guide has said ... Like he gave me an example was : When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options .. So , there has to be a general algo that applies to all .. Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall:)

                                  C 1 Reply Last reply
                                  0
                                  • J Jomy John

                                    No..im just quoting the stuff my project guide has said ... Like he gave me an example was : When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options .. So , there has to be a general algo that applies to all .. Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall:)

                                    C Offline
                                    C Offline
                                    Christian Graus
                                    wrote on last edited by
                                    #20

                                    Jomy John wrote: When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options .. Yes, there are options. And for each one, the image is encoded differently, that's what makes them options Jomy John wrote: So , there has to be a general algo that applies to all .. Bollocks. The only thing that is general is that you need to use a disk API to write the files, and you need in every case to access the bits of the image, which would generally mean you used a DIBSection, which in turn means you have a pointer to the bitmap. The only algorithm I can thing of is how you traverse those bits. Jomy John wrote: Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall How in the HELL can he test you on something he 'read in a book 7 years ago' ? If he does not know the answer, if he does not have, or cannot produce a solution, how will he mark yours ? Christian Graus - Microsoft MVP - C++

                                    J 1 Reply Last reply
                                    0
                                    • C Christian Graus

                                      Jomy John wrote: When u open a paint application ...draw sumthing in it ..and the "Save As" option gives options to save as a number of file options .. Yes, there are options. And for each one, the image is encoded differently, that's what makes them options Jomy John wrote: So , there has to be a general algo that applies to all .. Bollocks. The only thing that is general is that you need to use a disk API to write the files, and you need in every case to access the bits of the image, which would generally mean you used a DIBSection, which in turn means you have a pointer to the bitmap. The only algorithm I can thing of is how you traverse those bits. Jomy John wrote: Sadly, he had read it in a book ,6-7 yrs back...hehee..whose name he cant recall How in the HELL can he test you on something he 'read in a book 7 years ago' ? If he does not know the answer, if he does not have, or cannot produce a solution, how will he mark yours ? Christian Graus - Microsoft MVP - C++

                                      J Offline
                                      J Offline
                                      Jomy John
                                      wrote on last edited by
                                      #21

                                      I really dont know what to do or say :(

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups