archive-com.com » COM » E » EFG2.COM

Total: 878

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • efg's Image Processing -- CryptImage Lab Report
    TBitmap i INTEGER j INTEGER RandomValue BYTE rowIn pByteArray rowOut pByteArray ScanlineByteCount INTEGER BEGIN BitmapDecrypted TBitmap Create BitmapDecrypted Width BitmapEncrypted Width BitmapDecrypted Height BitmapEncrypted Height BitmapDecrypted PixelFormat BitmapEncrypted PixelFormat Copy palette if palletized image IF BitmapEncrypted PixelFormat IN pf1bit pf4bit pf8bit THEN BitmapDecrypted Palette CopyPalette BitmapEncrypted Palette This finds the number of bytes per scanline regardless of PixelFormat ScanlineByteCount ABS Integer BitmapEncrypted Scanline 1 Integer BitmapEncrypted Scanline 0 TRY RandSeed StrToInt EditSeedDecrypt Text EXCEPT RandSeed 79997 use this prime number if entry is invalid END FOR j 0 TO BitmapEncrypted Height 1 DO BEGIN RowIn BitmapEncrypted Scanline j RowOut BitmapDecrypted Scanline j FOR i 0 TO ScanlineByteCount 1 DO BEGIN RandomValue Random 256 0 255 value RowOut i RowIn i XOR RandomValue END END ImageDecrypted Picture Graphic BitmapDecrypted EditSeedDecrypt Enabled TRUE END DecryptImage In the pf24bit example shown at the top of this page the encrypted image gives no hint as to what colors might be present in the original image For palletized images i e pf1bit pf4bit pf8bit the palette is copied from the original image to the encrypted image and only the scanlines are encrypted Because some information about the image is contained in the palette encrypting the palette may also be a good idea but that was not done in this project For example only the colors of the pf1bit Smiley from the Single Bit Bitmaps Lab Report are present in the encrypted form see below Hiding these colors by encrypting the palette entries may be desirable Smiley Encrypted Smiley Using a different Encrypt Seed Number for each and every encrypted image is quite important If the same Encrypt Seed Number is used for two images some information about both images can be learned without the Encrypt Seed Number For example assume you have two images A and B Original Images A B If you encrypt both of these images with the Encrypt Seed Number 19937 the results seem to hide the images Images Encrypted Using Seed 19937 A19937 B19937 But now if you take both of these images and without any knowledge of the original encryption key perform certain operations with the images some information about the original images can be seen For example if you use XOR with corresponding color components for each pixel R G B R1 XOR R2 G1 XOR G2 B1 XOR B2 some information about the original can be extracted In particular many traces of image B can be seen A19937 XOR B19937 This image is the equivalent to XORing the original images A and B A XOR B If we assume R is the random sequence of bits this is the math that explains why the randomness does not hide the composite image A XOR B A XOR R XOR B XOR R A XOR B The solution is to use unique random sequences with A and B A XOR R1 XOR B XOR R2 A XOR B This emphasizes why a unique key should be used with each image

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/CryptImage.htm (2016-02-14)
    Open archived version from archive


  • efg's Image Processing -- Rotate Scanline Lab Report
    of pixel adjustment Assumes input BitmapOriginal has PixelFormat pf24bit FUNCTION RotateBitmapMethod1 CONST BitmapOriginal TBitmap CONST iRotationAxis jRotationAxis INTEGER CONST AngleOfRotation DOUBLE radians TBitmap VAR cosTheta EXTENDED i INTEGER iOriginal INTEGER iPrime INTEGER j INTEGER jOriginal INTEGER jPrime INTEGER RowOriginal pRGBTripleArray RowRotated pRGBTRipleArray sinTheta EXTENDED BEGIN The size of BitmapRotated is the same as BitmapOriginal PixelFormat must also match since 24 bit GBR triplets are assumed in ScanLine RESULT TBitmap Create RESULT Width BitmapOriginal Width RESULT Height BitmapOriginal Height RESULT PixelFormat pf24bit Force this Get SIN and COS in single call from math library sincos AngleOfRotation sinTheta cosTheta If no math library then use this sinTheta SIN AngleOfRotation cosTheta COS AngleOfRotation Step through each row of rotated image FOR j RESULT Height 1 DOWNTO 0 DO BEGIN RowRotated RESULT Scanline j jPrime j jRotationAxis FOR i RESULT Width 1 DOWNTO 0 DO BEGIN iPrime i iRotationAxis iOriginal iRotationAxis ROUND iPrime CosTheta jPrime sinTheta jOriginal jRotationAxis ROUND iPrime sinTheta jPrime cosTheta Make sure iOriginal jOriginal is in BitmapOriginal If not assign blue color to corner points IF iOriginal 0 AND iOriginal BitmapOriginal Width 1 AND jOriginal 0 AND jOriginal BitmapOriginal Height 1 THEN BEGIN Assign pixel from rotated space to current pixel in BitmapRotated RowOriginal BitmapOriginal Scanline jOriginal RowRotated i RowOriginal iOriginal END ELSE BEGIN RowRotated i rgbtBlue 255 assign corner color RowRotated i rgbtGreen 0 RowRotated i rgbtRed 0 END END END END RotateBitmapMethod1 In the original version of this program I went to great length to use the center of the pixel as the location of the pixel Method 2 uses location i 0 5 j 0 5 for pixel i j and then does the reverse lookup as described above Method 3 was like Method 2 but attempted to used more integer math If you multiply i 0 5 j 0 5 by 2 you can work in space 2i 1 2j 1 Method 3 effectively is a more complicated way to implement Method 2 unfortunately Method 3 was the way Rotate ScanLine was implemented This confused several people so I restructured this Lab to show the Simple method The timing differences between Methods 1 3 doesn t seem to be that significant Aliasing effects of rotating a 24 bit color bitmap usually aren t noticed for a real world image but may be noticed if rotating a bitmap with lines or sharp edges To reduce such aliasing a bilinear interpolation would be an improvement of the existing algorithm that just picks the closest pixel but it ll be slower For even a better way to rotate a bitmap but it ll be somewhat slower see High Accuracy Rotation of Images in Computer Vision Graphics and Image Processing Vol 54 No 4 July 1992 pp 340 344 For other details about image rotation including multipass rotation see section 8 5 in High Performance Computer Imaging In Windows NT the plgblt parallelogram block transfer API call can be used for bitmap rotation if the RC BITBLT is supported by a

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/RotateScanline.htm (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- Flip Reverse Rotate Lab Report
    This is not a limitation of ScanLine Discussion The ModifyOriginalImage procedure is called when the BMP file is read or when the Flip or Reverse checkboxes change or when the Method changes This procedure calls a BitmapFlipReverse function which flips or reverses the original bitmap based on which Method is selected Each BitmapFlipReverse function creates a new bitmap that must be freed when the modified bitmap is no longer needed According to a July 25 1997 post by David Ullrich to comp lang pascal delphi misc in response to a question How to flip a bitmap David suggests You can flip stuff using CopyRect or BitBlt or StretchBl t or whatever by using rects that have Left to the right of Right and Top below Bottom as in say Canvas CopyRect Rect 0 0 300 300 Canvas Rect 300 0 0 300 If you don t need to process the pixels while flipping or reversing them then this may be a good alternative This advice was quite accurate except for a minor 1 adjustment was necessary shown in the code whenever a flip or reversal takes place The CopyRect method calls the StretchBlt API call A separate BitmapFlipReverseStretchBlt routine was written while trying to find why there was an off by 1 error which was solved by the 1 adjustment seen in the code This separate routine can be used for quick comparison of how to use CopyRect versus StretchBlt Thomas Kowalski suggested a slightly different approach with routines that operate much more quickly See his SpiegellnHorizontal Horizontal Mirror SpiefelLnVertikal Vertical Mirror Drehen90Grad 90 degree rotation Drehen180Grad 180 degree rotation and Drehen270Grad 270 degree rotation routines in his Unit7 Dave Shapiro s unit for rotating TBitmaps 90 180 or 270 degrees Works in D1 D2 D3 and D4 Not entirely

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/FlipReverseRotate.htm (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- Tween
    of the Trackbar is changed Select the number of images for a sequence e g 25 with the spinedit box and press the Create Sequence button Caution this can exhaust your virtual memory resources if a large number of large images is computed Move the Trackbar left or right to view the pre computed Tween images manually Press the Show Sequence button to show the sequence of Tween images as quickly as possible If necessary adjust the time delay before pressing the Show Sequence button to slow the sequence of images Loading a new image or pressing the Reset button will reset the sequence of images and return to calculating each Tween image Discussion Logic in the ButtonLoadClick procedure only allows Tween images to be computed if the height and width of both images are the same Also both images must have pf24bit PixelFormat The heart of creating the Tween image is the CreateTweenBitmap function This function accepts two TBitmap s and two positive integer weights The sum of the cardinal weights should be greater than zero if the sum is zero a white image is returned Each Tween pixel is formed by the weighted sum of the R G and B components e g Pixel Tween Weight A Pixel A Weight B Pixel B DIV Weight A Weight B See the WeightPixels function In the twCalculate mode the Tween weights for the A and B are set by the Trackbar as TrackBarTween Max TrackBarTween Position for Image A and TrackBarTween Position for Image B Pressing the Create Sequence button results in the creation of an in memory TList of TBitmap s and changes the program to the twShowList mode Caution Creating a large TList of large images can give your machine s virtual memory management system a real workout

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/Tween.htm (2016-02-14)
    Open archived version from archive

  • efg's Tech Note: Slide Show:  Creating a Delphi Image Management Utility
    controls the display of images in the TImage component Table 2 The Speed Buttons The controls are very simple the first or last image can be quickly selected using the end controls The sequence can be displayed in forward or reverse direction using the green play buttons The yellow pause button can be used at any time to stop the display of a sequence The Click responses for these speed buttons is shown next procedure TFormSlideShow SpeedButtonFirstOneClick Sender TObject begin TimerStep Enabled FALSE TrackBarProgress Position 0 DisplayCurrentImage end procedure TFormSlideShow SpeedButtonPlayClick Sender TObject begin Delta is 1 for forward direction 1 for reverse direction Delta Sender AS TSpeedButton Tag TimerStep Enabled TRUE end procedure TFormSlideShow SpeedButtonLastOneClick Sender TObject begin TimerStep Enabled FALSE TrackBarProgress Position FileList Count 1 DisplayCurrentImage end procedure TFormSlideShow SpeedButtonPauseClick Sender TObject begin TimerStep Enabled FALSE DisplayCurrentImage also enables Print button end The TSpinEdit control another Samples component that Borland should document online specifies the frequency that images should change in the sequence using a TTimer Every time the TTimer fires the image sequence goes forward or backward one image procedure TFormSlideShow TimerStepTimer Sender TObject VAR Index INTEGER begin Use separate index variable to avoid range error with TrackBarProgress Position Index TrackBarProgress Position Delta IF Index 0 OR Index FileList Count 1 THEN TimerStep Enabled FALSE ELSE TrackBarProgress Position Index DisplayCurrentImage end Note that the progress through the sequence is shown by the TTrackBar at the top at all times which is shown in the routine that updates the display of an image PROCEDURE TFormSlideShow DisplayCurrentImage VAR BitmapRaw TBitmap BitmapToDisplay TBitmap begin IF ComboBoxColorSpace ItemIndex 0 AND NOT CheckBoxMonochrome Checked AND NOT CheckBoxInvert Checked THEN Shortcut for normal RGB image to reduce overhead ImageDisplay Picture LoadFromFile FileList Strings TrackBarProgress Position ELSE BEGIN This approximates behavior of Picture LoadFromFile One difference here is that everything is a TBitmap while above certain files e g ICOs cannot be manipulated So an ICO can be stretched only when it is not shown in full RGB color I know this really doesn t make any sense BitmapRaw LoadGraphicsFile FileList Strings TrackBarProgress Position TRY BitmapToDisplay ExtractImagePlane ColorPlane NOT CheckBoxMonochrome Checked CheckBoxInvert Checked BitmapRaw TRY ImageDisplay Picture Graphic BitmapToDisplay FINALLY BitmapToDisplay Free END FINALLY BitmapRaw Free END END LabelImageName Caption Image IntToStr 1 TrackBarProgress Position ExtractFilename FileList Strings TrackBarProgress Position IntToStr ImageDisplay Picture Width by IntToStr ImageDisplay Picture Height pixels Update state of buttons SpeedButtonFirstOne Enabled TrackBarProgress Position 0 SpeedButtonPlayReverse Enabled TrackBarProgress Position 0 SpeedButtonLastOne Enabled TrackBarProgress Position FileList Count 1 SpeedButtonPlayForward Enabled TrackBarProgress Position FileList Count 1 SpeedButtonPause Enabled TimerStep Enabled BitBtnPrint Enabled NOT TimerStep Enabled end Note the polymorphic behavior of the Picture LoadFromFile method above This method can be used to load and display a graphic of any kind that Delphi understands This feature prevents any manipulation of certain files such as the ICO files The ELSE clause bypasses the use of the poloymorphic TPicture and replaces it with a LoadGraphicsFile conversion see below for details to a TBitmap regardless of

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/SlideShow.htm (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- Magnifying Glass Lab Report
    TBitmap VAR Image TPicture BEGIN Result nil if FileExists Filename then begin Result TBitmap Create try Image TPicture Create try Load image let TPicture worry about the image type Image LoadFromFile Filename Try converting image to bitmap try Result Assign Image Graphic except Image didn t support conversion to TBitmap Draw image on bitmap instead Result Width Image Graphic Width Result Height Image Graphic Height Result PixelFormat pf24bit Result Canvas Draw 0 0 Image Graphic end finally Image Free end except Result Free raise end The following appears to be needed for the circular magnifier for some not all GIF files and for pf8bit TBitmaps Some GIF files do not appear correctly without this and pf8bit bitmaps do not have real time updates without forcing this This may not be desirable in other programs This is an experimental fix I wish I knew why this is necessary efg 21 Feb 99 IF ForcePf24bit AND RESULT PixelFormat pf24bit THEN Result PixelFormat pf24bit end END LoadGraphicFile I added the ForcePf24bit parameter to Anders routine this will be discussed below Look at the TMagnifier ShowMagnifier method for details of how the magnification process works A brief outline appears here The diameter of the magnified area times the magnification factor is a constant For example if the area of interest had a diameter of 30 pixels at a 2X magnification 30 2 60 only 15 pixels would be selected at a 4X magnification 15 4 60 With no magnification 1X this would be a 60 pixel diameter area 60 1 60 The calculation of a diameter is limited by the integer arithmetic of pixel sizes An in memory Bitmap is read as part of the OpenPictureDialog Execute processing in the ButtonLoadImageClick method To avoid working with a variety of pixel formats and palettes all the files read by LoadGraphicsFile in the GraphicsConversionsLibrary PAS unit are converted to a pf24bit pixel format This means that correct colors are only displayed when using a high color or true color display mode For the square magnifier the original in memory bitmap is first copied to a new ModifiedBitmap A small square area of the original in memory Bitmap around the point X Y from the MouseDown or MouseMove event is stretched onto a larger area of the ModifiedBitmap The ModifiedBitmap is then displayed in the ImageOnForm TImage Extra work is needed for the circular magnifier A new ModifiedBitmap is first copied from the in memory Bitmap as described above A CircularMask bitmap is created with a solid black background and a filled in white circle of appropriate size CopyRect with CopyMode cmSrcAnd converts the CircularMask to have an enlarged circular area from the original image with a black area around this circle An And of a black 0 for R G and B area from the mask results in a black area An And of a white 255 FF for R G and B area from the mask selects a circular area of interest from the in

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/Magnifier.htm (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- Pixel Profile Lab Report
    on the mouse button move and then release If desired removed the line by pressing on the Erase Tool button View the Pixel Profile data by selecting the Data Tab Sheet The X Y coordinates shown in the data table are truncated to look up the R G B values of the pixels along the Pixel Profile Line Note that the first and last X Y coordinates reflect the middle of the pixel location e g 266 5 311 5 to 348 5 404 5 instead of 266 311 to 348 404 The I Intensity H Hue S Saturation and V Value values are computed from the R G B values Data can be cut from this screen for analysis in other applications See Discussion below Select the Graphs Tab Sheet to view the graphical Pixel Profiles Note the Pixel Slice is shown along the top of the graph Use the check boxes to select which graphs are shown Select the Print button to print the graph Discussion The data or graph provided by the Pixel Profile can be useful in analyzing an image For example the number of kernels of corn maize in the image above can be determined by analyzing the Pixel Profile The data from the Pixel Profile shown above can be cut and paste into another application or even saved to an ASCII text file using an editor This data can be imported into an Excel Spreadsheet The following shows the analysis of the the Red data profile The Index and Red columns are from the Data Tab Sheet shown above The Smooth column is the average Red index 2 Red index 1 Red index Red index 1 Red index 2 which is used to make the technique less sensitive to noise in the data The Slope column is Delta Y Delta X which in this case is simply Smooth index Smooth index 1 The Sign column is the sign 1 0 1 of the Slope column A peak is near the point where the slope changes from increasing 1 to decreasing 1 The 1 1 column identifies when a peak occurs In this image these peaks correspond to each kernel in the maize corn This is summarized in the following graph All 15 peaks i e kernels of corn in the data were found using this technique Notes about the program The FormCreate includes the assignment OpenPictureDialog Filter GraphicFilter TGraphic to make sure all registered graphic file formats especially JPG and GIF can be read using the TOpenPictureDialog The polymorphic TPicture was used to load images into a TBitmap in ButtonLoadImageClick The PixelFormat is forced to pf24bit when an image is loaded The LineLibrary unit has a number of routines for working with lines In particular the NearLine function is used with the Select Tool to move a line During the mouse move events the cursor movement is restricted to be within the image using the RestrictCusorToDrawingArea routine in LineLibrary The routine CreateProfileLine creates the

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/PixelProfile.htm (2016-02-14)
    Open archived version from archive

  • efg's Image Processing -- HistoStretchGrays Lab Report
    of any PixelFormat to a pf24bit PixelFormat this avoids working with palettes Each 24 bit color pixel has 8 bits of red 8 bits of green and 8 bits of blue A color image can be converted to a gray scale value by computing the Y value for each color pixel Y 0 299R 0 587G 0 114B This Y value is the grayscale component in the YIQ color space used in NTSC television The weights reflect the eye s brightness sensitivity to the color primaries Other methods could have been used for this color to grayscale conversion Often for convenience an Intensity value is used I R G B 3 Once this Y value is computed this Y value is then assigned back to each of the R G B components of the color pixel RGB i i i where i 0 255 yields a grayscale Working with gray scale images in high color or true color environment allows the use of all values 0 255 without special API calls to establish a 256 gray scale palette By default Windows reserves 20 of the 256 colors in 256 color display mode and a special API call is needed to reclaim 18 of the 20 colors Two of the colors cannot be redefined but these colors are black and white and they are needed for the complete 256 gray scale palette anyway When you process a gray scale image like the faces 211 JPG and 319 JPG derived from the Faces database the program displays the number of shades of gray to the right of the Read button When you process a color image such as the Mandrill BMP in the Mandrill ZIP file the program displays the original number of colors and the resulting number of shades of gray to the right of the Read button After reading the image file the histogram frequency distribution is computed as well as a number of other statistics When a histogram has a single dominant peak these statistics are often helpful in describing this peak The range of interest is computed from the histogram based on a percentage parameter In the examples shown above the 1 and 99 values are determined using the histogram Normally this range of interest OriginalRange is stretched to the full 0 to 255 range to improve the contrast of the image The percentage value in effect defines how many pixels are forced to be at 0 black and 255 white The StretchFactor which is normally 1 00 is used as follows to compute a histogram ScaleFactor StretchedRange OriginalRange ROUND StretchFactor 255 OriginalRange ScaleFactor StretchedRange OriginalRange The intensity of each pixel is inspected and re assigned based on this ScaleFactor NewIntensity ROUND ScaleFactor OldIntensity OriginalRangeLeft Each NewIntensity value is forced to 0 if below 0 and forced to 255 if above 255 Notes about the HistoStretchGrays program The FormCreate includes the assignment OpenPictureDialog Filter GraphicFilter TGraphic to make sure all registered graphic file formats especially JPG and GIF

    Original URL path: http://www.efg2.com/Lab/ImageProcessing/HistoStretchGrays.htm (2016-02-14)
    Open archived version from archive



  •