Squares

General FreeBASIC programming questions.
albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 10, 2012 2:24

@Dodicat

Thanks , I tried running the Gaussian Blur in reverse and it just faded to black..

===========================================================================================
@BasicCoder2
sRed = sRed + r * (Gaussian(xx+2,yy+2)*1.04)
sGrn = sGrn + g * (Gaussian(xx+2,yy+2)*1.04)
sBlu = sBlu + b * (Gaussian(xx+2,yy+2)*1.04)

Using 1.04 as a multiplier keeps it from fading to black...It stays bright thru the whole range of blurs..
Both yours and Richards cures to shrinkage work about the same..
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 10, 2012 4:35

http://en.wikipedia.org/wiki/Gaussian_blur

"When converting the Gaussian’s continuous values into the discrete values needed for a kernel, the sum of the values will be different from 1. This will cause a darkening or brightening of the image. To remedy this, the values can be normalized by dividing each term in the kernel by the sum of all terms in the kernel."

Which for this kernel would be 263?

Code: Select all

sRed = sRed\263
sGrn = sGrn\263
sBlu = sBlu\263
albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 10, 2012 18:38

@BasicCoder2

Thanks, I was trying plugging experimentally, different values into the Kernel output to keep It from darkening. I didn't understand how the Kernel was working..


So if I change the Kernel Matrix then I have to sum the Kernel Matrix and use that as the Divisor...


Now on to Sharpening or reversing the blur...
Do you have any sharpening code or UnGaussian code lying around?
I tried reversing the Gaussian by moving the Kernel big numbers to the outside and converging to 1 in the center and it didn't work, it just went straight to black..
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 10, 2012 19:36

albert wrote:@BasicCoder2
Now on to Sharpening or reversing the blur...
Do you have any sharpening code or UnGaussian code lying around?
I tried reversing the Gaussian by moving the Kernel big numbers to the outside and converging to 1 in the center and it didn't work, it just went straight to black..


May I just say I find placing this subject in this long misc thread seems a bad idea. It is better the subject title fits the subject and is worded to find the subject matter easy to find in a Search.

Blurring loses information so I don't think you can reverse it. What is your purpose in blurring it in the first place? One reason others use it is to reduce noise before doing an edge detection process.

One issue I had was what image format to use for the image processing routines. One reason I like FreeBasic is the ease of using bitmaps. The example below however uses an array of uintegers converted to that format from the loaded bitmap. I find the code is easier to follow for a novice. However the array does not contain information about things like the width and height which is an issue if your program uses different sized images.

Another was to use a pixel type to avoid unpacking the argb values.

Code: Select all

type Pixel
  as integer r
  as integer g
  as integer b
  as integer a
end type



One way you can sharpen up an image is with a high pass filter.

Code: Select all

Const iWIDTH = 640     ,'<--- change to fit dimensions of your own image
Const iHEIGHT = 480
 
ScreenRes 800,480,32

'processing routines assume images exist as uinteger arrays
Dim shared As Any Ptr lpImage
lpImage = ImageCreate(iWIDTH,iHEIGHT) 'used to load/display/save images as bitmaps

'global variables store image arrays
Dim Shared As Uinteger image1(iWIDTH,iHEIGHT)
Dim Shared As Uinteger image2(iWIDTH,iHEIGHT)


Sub loadImage(image1() as uinteger,file as string)
    Dim As integer i,imgW,imgH
    dim as uinteger ptr iPtr
    bload file,lpImage
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy lpImage into image1()
    i = 0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            image1(x,y) = iPtr[i]
            i = i + 1
        Next x
    Next y   
End Sub

Sub displayImage(image1() As Uinteger)
    Dim As Integer i,imgW,imgH
    dim as uinteger ptr iPtr
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy image1() into lpImage
    i=0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            iPtr[i] = image1(x,y)
            i = i + 1
        Next x
    Next y
    Put (0,0), lpImage,Pset
End Sub

' ========= create HFMASK =========
dim shared as integer HFmask(3,3)
for j as integer = 0 to 2
    for i as integer = 0 to 2
        read HFmask(i,j)
    next i
next j
data -1,-1,-1
data -1, 9,-1
data -1,-1,-1
'==================================
 
Sub HFbypass(image1() as uinteger, image2() as uinteger)
   dim as integer pixel,r,g,b,sRed,sGrn,sBlu
   for y as integer = 1 to iHEIGHT-2
      for x as integer = 1 to iWIDTH-2
          sRed = 0
          sGrn = 0
          sBlu = 0
          for yy as integer = -1 to 1
              for xx as integer = -1 to 1
                 
                  'extract colors
                  pixel = image2(x+xx,y+yy)
                  r = pixel shr 16 and 255
                  g = pixel shr  8 and 255
                  b = pixel and 255
                 
                  sRed = sRed + r * HFmask(xx+1,yy+1)
                  sGrn = sGrn + g * HFmask(xx+1,yy+1)
                  sBlu = sBlu + b * HFmask(xx+1,yy+1)
                 
              next xx
          next yy
          if sRed<0 then sRed = 0
          if sRed>255 then sRed = 255
          if sGrn<0 then sGrn = 0
          if sGrn>255 then sGrn = 255
          if sBlu<0 then sBlu = 0
          if sBlu>255 then sBlu = 255
          image1(x,y) = rgb(sRed,sGrn,sBlu)
      next x
   next y
End Sub

' =======  MAIN PROGRAM =========


    loadImage(image1(),"C:\FreeBasic\bitmaps\Views\view.bmp") '<---  replace with a file path to your own image
    displayImage(image1())       'view original
    sleep
    HFbypass(image2(),image1())
    displayImage(image2())       'view result
    sleep



imageDestroy(lpImage)

End
albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 10, 2012 21:50

@BasicCoder2

That looks like the GIMP sharpen..
The best sharpener algorithim is in the old XView commercial photo manipulator program that cam free with RedHat 5.0

In zooming in on pictures you need to do:
1) Blur to 1
2) double the size
3) sharpen
4) oilify to .5 (oilify spreads the pixels out a little smearing them together filling in the edges.)

And repeat the steps till the image is the size you want,
It will zoom without pixelating, following the above steps.

But GIMPS sharpen does edge-detect/ enhance and screws the sharpening up.
So I use to use XView to sharpen , and ImageMajik to oilify.

I was wanting to put all the above into a single zoom program, to avoid all the saving and loading with each step..
Its a Zooming technique I invented back in the late 90's when I was running redhat 5.0


Thanks for your help so far!!
Richard
Posts: 2753
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Nov 10, 2012 21:54

@ Albert.
If you dispose of necessary image information then you cannot regenerate it correctly. It all comes back to a fundamental rule of signal processing called the Nyquist-Shannon Sampling Theorem. http://en.wikipedia.org/wiki/Nyquist%E2 ... ng_theorem

Fundamentally, if you reduce the number of data points (pixels) used to represent an image you will eliminate the high frequency (detailed) information from that image. It is not then theoretically possible to recover that lost information.

If you apply a spatial low pass filter to an image by reducing high frequencies to say one 10th amplitude then it is possible to recover that information by applying a conjugate filter. However that requires you do not reduce the number of pixels used to represent that image during the process, and that you use enough bits to represent each pixel.

In the audio field, Dolby is the name given to the process of initially increasing high frequency amplitude so that on replay it can be attenuated back to natural. Since the tape recording process noise was dominated by high frequency noise, the final replay filter attenuated the inherent process noise while reconstructing the original. The bandwidth of the recording was never reduced so reconstruction was possible.
albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 10, 2012 22:01

@Richard
@BasicCoder2

BasicCoder2 I put both your programs together the Blur and Sharpen ,
use
"`" to restore orig
"1" to blur
"2" to sharpen

after several blurs you can almost recover the whole picture..

Code: Select all


Const iWIDTH = 640
Const iHEIGHT = 480
ScreenRes 800,480,32

'processing routines assume images exist as uinteger arrays
Dim shared As Any Ptr lpImage
lpImage = ImageCreate(iWIDTH,iHEIGHT) 'used to load/display/save images as bitmaps

'global variables store image arrays
Dim Shared As Uinteger image1(iWIDTH,iHEIGHT)
Dim Shared As Uinteger image2(iWIDTH,iHEIGHT)


Sub loadImage(image1() as uinteger,file as string)
    Dim As integer i,imgW,imgH
    dim as uinteger ptr iPtr
    bload file,lpImage
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy lpImage into image1()
    i = 0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            image1(x,y) = iPtr[i]
            i = i + 1
        Next x
    Next y   
End Sub

Sub displayImage(image1() As Uinteger)
    Dim As Integer i,imgW,imgH
    dim as uinteger ptr iPtr
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy image1() into lpImage
    i=0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            iPtr[i] = image1(x,y)
            i = i + 1
        Next x
    Next y
    Put (0,0), lpImage,Pset
End Sub

' ========= create HFMASK =========
dim shared as integer HFmask(3,3)
for j as integer = 0 to 2
    for i as integer = 0 to 2
        read HFmask(i,j)
    next i
next j
data -1,-1,-1
data -1, 9,-1
data -1,-1,-1
'==================================

Sub HFbypass(image1() as uinteger, image2() as uinteger)
   dim as integer pixel,r,g,b,sRed,sGrn,sBlu
   for y as integer = 1 to iHEIGHT-2
      for x as integer = 1 to iWIDTH-2
          sRed = 0
          sGrn = 0
          sBlu = 0
          for yy as integer = -1 to 1
              for xx as integer = -1 to 1
                 
                  'extract colors
                  pixel = image2(x+xx,y+yy)
                  r = pixel shr 16 and 255
                  g = pixel shr  8 and 255
                  b = pixel and 255
                 
                  sRed = sRed + r * HFmask(xx+1,yy+1)
                  sGrn = sGrn + g * HFmask(xx+1,yy+1)
                  sBlu = sBlu + b * HFmask(xx+1,yy+1)
                 
              next xx
          next yy
          if sRed<0 then sRed = 0
          if sRed>255 then sRed = 255
          if sGrn<0 then sGrn = 0
          if sGrn>255 then sGrn = 255
          if sBlu<0 then sBlu = 0
          if sBlu>255 then sBlu = 255
          image1(x,y) = rgb(sRed,sGrn,sBlu)
      next x
   next y
End Sub
' ========= create Gaussian 5x5 KERNEL =========
dim shared as integer Gaussian(5,5)
for j as integer = 0 to 4
    for i as integer = 0 to 4
        read Gaussian(i,j)
    next i
next j
data 1, 4, 7, 4,1
data 4,16,26,16,4
data 7,16,41,16,7
data 4,16,26,16,4
data 1, 4, 7, 4,1
'==================================
Sub GaussianBlur(image1() as uinteger, image2() as uinteger)
   dim as integer pixel,r,g,b,sRed,sGrn,sBlu
   dim as integer px,py  'adjusted coordinates for overflow
   for y as integer = 0 to iHEIGHT-1
      for x as integer = 0 to iWIDTH-1
          sRed = 0
          sGrn = 0
          sBlu = 0
          for yy as integer = -2 to 2
              for xx as integer = -2 to 2
                  px = x + xx
                  py = y + yy
                 
                  if px<0 then px = abs(px) : if px>(iWidth-1)  then px=iWidth-xx-1
                  if py<0 then py = abs(py) : if py>(iHeight-1) then py=iHeight-yy-1
                  'extract colors
                  pixel = image2(px,py)
                  r = pixel shr 16 and 255
                  g = pixel shr  8 and 255
                  b = pixel and 255
                 
                  sRed = sRed + r * Gaussian(xx+2,yy+2)
                  sGrn = sGrn + g * Gaussian(xx+2,yy+2)
                  sBlu = sBlu + b * Gaussian(xx+2,yy+2)
                 
              next xx
          next yy
         
          sRed = sRed\253
          sGrn = sGrn\253
          sBlu = sBlu\253
         
          if sRed<0 then sRed = 0 : if sRed>255 then sRed = 255
          if sGrn<0 then sGrn = 0 : if sGrn>255 then sGrn = 255
          if sBlu<0 then sBlu = 0 : if sBlu>255 then sBlu = 255
         
          image1(x,y) = rgb(sRed,sGrn,sBlu)
         
      next x
   next y
End Sub
sub copy(image1() as uinteger, image2() as uinteger)
    for y as integer = 0 to iHeight-1
        for x as integer  = 0 to iWidth-1
            image1(x,y)=image2(x,y)
        next x
    next y
end sub

' =======  MAIN PROGRAM =========
dim as string key
    loadImage(image1(),"C:\USB\MY-FB-PROGRAMS-023\Dodicat\Dodicat_stitch-up\short-hair-2.bmp")
    displayImage(image1())       'view original
    'loadImage(image1(),"C:\FreeBasic\bitmaps\Views\view1.bmp")

displayImage(image1())       'view original
do
    key = inkey
    if key = "1" then
        GaussianBlur(image2(),image1())
        displayImage(image1())       'view original
        copy(image1(),image2())      'copy back to start
    end if
    if key = "2" then
        HFbypass(image2(),image1())
        displayImage(image1())       'view original
        copy(image1(),image2())      'copy back to start
    end if
    if key="`" then
        loadImage(image1(),"C:\USB\MY-FB-PROGRAMS-023\Dodicat\Dodicat_stitch-up\short-hair-2.bmp")
        displayImage(image1())       'view original
    end if
    sleep
loop until key=chr(27)

imageDestroy(lpImage)

End

albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 11, 2012 1:11

Now its on to finding the Oilify algorithim ,

If I remember correctly ImagMagik had the best oilify algo, that why I was using it.

With the steps I mentioned above, you can take 75x75 bmp's or smaller , and blow them up to desktop size, without losing any info or pixelating them.

The GIMP for windows has the Oilify algo compiled to an Oilify.exe .
I downloaded GIMP_2.8 Linux sources and can't find the Oilify code or script anywhere in the source..

I'll try again modifying Dodicats ReSizer..
I might not need the blur and sharpen, but I'm sure they will come in handy somewhere..
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 11, 2012 10:28

albert wrote:Now its on to finding the Oilify algorithim ,
If I remember correctly ImagMagik had the best oilify algo, that why I was using it.

Unfortunately without knowing the algorithm, or having it in a usable image processing library, it isn't of much use in your own programs. Same goes for the blur and sharpen algorithms.

This is the only image to oil painting algorithm I could find,

http://www.codeproject.com/Articles/471 ... aintEffect

And this is my attempt to translate it to FreeBasic, it seems to work.

Code: Select all

Const iWIDTH = 640
Const iHEIGHT = 480
 
ScreenRes 800,480,32

'processing routines assume images exist as uinteger arrays
Dim shared As Any Ptr lpImage
lpImage = ImageCreate(iWIDTH,iHEIGHT) 'used to load/display/save images as bitmaps

'global variables store image arrays
Dim Shared As Uinteger image1(iWIDTH,iHEIGHT)
Dim Shared As Uinteger image2(iWIDTH,iHEIGHT)


Sub loadImage(image1() as uinteger,file as string)
    Dim As integer i,imgW,imgH
    dim as uinteger ptr iPtr
    bload file,lpImage
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy lpImage into image1()
    i = 0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            image1(x,y) = iPtr[i]
            i = i + 1
        Next x
    Next y   
End Sub

Sub displayImage(image1() As Uinteger)
    Dim As Integer i,imgW,imgH
    dim as uinteger ptr iPtr
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy image1() into lpImage
    i=0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            iPtr[i] = image1(x,y)
            i = i + 1
        Next x
    Next y
    Put (0,0), lpImage,Pset
End Sub

sub oilify(image2() as uinteger,image1() as uinteger,radius as integer)
    dim as integer r,g,b,intensity,i,max,maxIndex
    intensity = 25
    dim as integer intensityCount(256)
    dim as uinteger pixel
    dim as integer sumR(256),sumG(256),sumB(256)
   
    for y as integer = 0 to iHeight-radius
        for x as integer = 0 to iWidth-radius
            'clear table of values
            for ii as integer = 0 to 255
                sumR(ii)=0
                sumG(ii)=0
                sumB(ii)=0
                intensityCount(ii)=0
            next ii
            'find intensity of rgb value and apply intensity level
            for yy as integer = -radius to radius
                for xx as integer = -radius to radius
                    pixel = image1(x+xx,y+yy)
                    r = pixel shr 16 and 255
                    g = pixel shr 8 and 255
                    b = pixel and 255
                    'find intensity of rgb value and apply intensity level
                    'intensity = (r+g+b)\3'*intensity)/255
                    intensity = (((r+g+b)/3.0)*25)/255
                    if intensity > 255 then
                        intensity = 255
                    end if
                    i = intensity
                    intensityCount(i)=intensityCount(i)+1
                    'sum of each pixel value is calculated
                    sumR(i) = sumR(i)+r
                    sumG(i) = sumG(i)+g
                    sumB(i) = sumB(i)+b
                next xx
            next yy
           
            'find intensity with highest occurence
            max = 0
            maxIndex = 0
            for ii as integer = 0 to 255
                if intensityCount(ii)>max then
                    max = intensityCount(ii)  'largest value so far
                    maxIndex = ii             'found at index ii
                end if
            next ii
           
            r = sumR(maxIndex)/max  'max = number of pixels with this intensity
            g = sumG(maxIndex)/max
            b = sumB(maxIndex)/max
           
            image2(x,y)=rgb(r,g,b)
           
        next x
    next y

end sub

sub copy(image1() as uinteger, image2() as uinteger)
    for y as integer = 0 to iHeight-1
        for x as integer  = 0 to iWidth-1
            image1(x,y)=image2(x,y)
        next x
    next y
end sub

' =======  MAIN PROGRAM =========
dim as string key
loadImage(image1(),"C:\FreeBasic\bitmaps\Views\view1.bmp")

    displayImage(image1())       'view original
    sleep
    oilify(image2(),image1(),2)  'radius = 2 (5x5 matrix)
    displayImage(image2())       'view result
    sleep


imageDestroy(lpImage)

End
Last edited by BasicCoder2 on Nov 13, 2012 5:31, edited 1 time in total.
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 11, 2012 10:48

albert wrote:With the steps I mentioned above, you can take 75x75 bmp's or smaller , and blow them up to desktop size, without losing any info or pixelating them.


Did you discover that by trial and error?

You may not lose information but you cannot get information that is not visible in the original 75x75 image.

So if you are trying to make a military grade zoom function as you claim there must be an image large enough to provide enough pixels for the numbers of a licence plate or pebbles in asphalt to be represented. So it is unclear to me what that has to do with starting with a 75x75 image which will never provide more detail (info) by making it larger.
Richard
Posts: 2753
Joined: Jan 15, 2007 20:44
Location: Australia

Re: Squares

Postby Richard » Nov 11, 2012 13:46

@ Albert.
What you can do is to take a 75x75 image and display it as say a 750x750 image. To do that you must interpolate the intermediate pixels between the known pixels. That interpolation can use any one of many techniques, commonly spline polynomials or Fourier transforms. First apply the interpolation through each of the 75 known pixels in each row to make a total of 750 in each row. Then perform interpolation vertically using the same method to generate all 750 columns.

There will be no additional information in the image, you will just not be able to see the edges of the pixels if you pick the right interpolation function.
albert
Posts: 4021
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: Squares

Postby albert » Nov 11, 2012 20:00

@BasicCoder2

I played around with it and it need more work, but is almost there...

I made the radius 1
And made the radius loops SINGLE ( -radius to +radius step radius/4 )

It needs to Oilify to .5 to just slightly smear the pixels to hide the sharpening.

Its still putiing in some off colors...Almost there!!

I'm just using my picture Dodicat got from my Yahoo or FaceBook account , its turning whites to yellow

Code: Select all

Const iWIDTH = 640
Const iHEIGHT = 480

ScreenRes 800,480,32

'processing routines assume images exist as uinteger arrays
Dim shared As Any Ptr lpImage
lpImage = ImageCreate(iWIDTH,iHEIGHT) 'used to load/display/save images as bitmaps

'global variables store image arrays
Dim Shared As Uinteger image1(iWIDTH,iHEIGHT)
Dim Shared As Uinteger image2(iWIDTH,iHEIGHT)


Sub loadImage(image1() as uinteger,file as string)
    Dim As integer i,imgW,imgH
    dim as uinteger ptr iPtr
    bload file,lpImage
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy lpImage into image1()
    i = 0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            image1(x,y) = iPtr[i]
            i = i + 1
        Next x
    Next y   
End Sub

Sub displayImage(image1() As Uinteger)
    Dim As Integer i,imgW,imgH
    dim as uinteger ptr iPtr
    ImageInfo lpImage,imgW,imgH,,,iPtr
    'copy image1() into lpImage
    i=0
    For y As Integer = 0 To iHEIGHT-1
        For x As Integer = 0 To iWIDTH-1
            iPtr[i] = image1(x,y)
            i = i + 1
        Next x
    Next y
    Put (0,0), lpImage,Pset
End Sub

sub oilify(image2() as uinteger,image1() as uinteger,radius as integer)
    dim as integer r,g,b,intensity,i,max,maxIndex
    intensity = 25
    dim as integer intensityCount(256)
    dim as uinteger pixel
    dim as integer sumR(256),sumG(256),sumB(256)
   
    for y as integer = radius to iHeight-radius
        for x as integer = radius to iWidth-radius
            'clear table of values
            for ii as integer = 0 to 255
                sumR(ii)=0
                sumG(ii)=0
                sumB(ii)=0
                intensityCount(ii)=0
            next ii
            'find intensity of rgb value and apply intensity level
            for yy as single = -radius to radius step radius/4
                for xx as single = -radius to radius step radius/4
                    pixel = image1(x+xx,y+yy)
                    r = pixel shr 16 and 255
                    g = pixel shr 8 and 255
                    b = pixel and 255
                    'find intensity of rgb value and apply intensity level
                    'intensity = ((r+g+b)/3.0)
                    intensity = (((r+g+b)/3.0)*25)/255
                   
                    if intensity > 255 then intensity = 255
                    if intensity <   1 then intensity = 1
                    i = intensity
                    intensityCount(i)=intensityCount(i)+1
                    'sum of each pixel value is calculated
                    sumR(i) = sumR(i)+r
                    sumG(i) = sumG(i)+g
                    sumB(i) = sumG(i)+b
                next xx
            next yy
           
            'find intensity with highest occurence
            max = 0
            maxIndex = 0
            for ii as integer = 0 to 255
                if intensityCount(ii)>max then
                    max = intensityCount(ii)  'largest value so far
                    maxIndex = ii             'found at index ii
                end if
            next ii
           
            r = sumR(maxIndex)/max  'max = number of pixels with this intensity
            g = sumG(maxIndex)/max
            b = sumB(maxIndex)/max
           
            image2(x,y)=rgb(r,g,b)
           
        next x
    next y

end sub

sub copy(image1() as uinteger, image2() as uinteger)
    for y as integer = 0 to iHeight-1
        for x as integer  = 0 to iWidth-1
            image1(x,y)=image2(x,y)
        next x
    next y
end sub

' =======  MAIN PROGRAM =========
dim as string key
'loadImage(image1(),"C:\FreeBasic\bitmaps\Views\view1.bmp")
loadImage(image1(),"C:\USB\MY-FB-PROGRAMS-023\Dodicat\Dodicat_stitch-up\short-hair-2.bmp")

    displayImage(image1())       'view original
    sleep
    oilify(image2(),image1(), .55 )  'radius = 2 (5x5 matrix)
    displayImage(image2())       'view result
    sleep
    sleep

imageDestroy(lpImage)

End



The smallest radius I could pass is .55
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 11, 2012 20:34

albert wrote:@BasicCoder2
Its still putiing in some off colors...Almost there!!


I tried the code project image of autumn leaves (hit PrintScrn and loaded into paint and cut out the image to save).
Yes there is something wrong going on as the greens seems to turn gray!!
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Re: Squares

Postby MichaelW » Nov 11, 2012 20:51

BasicCoder2 wrote:…but you cannot get information that is not visible in the original 75x75 image.

What if the image contains recognizable patterns that are not complete within the image?
BasicCoder2
Posts: 2753
Joined: Jan 01, 2009 7:03

Re: Squares

Postby BasicCoder2 » Nov 11, 2012 21:25

MichaelW wrote:
BasicCoder2 wrote:…but you cannot get information that is not visible in the original 75x75 image.

What if the image contains recognizable patterns that are not complete within the image?

You would have to give me an example.
A human can access their memory to recognize what should be there and fill it in for an enlarged hand drawn version of a small image which amounts to a program having all the extra detail elsewhere to guess what the crude pixel image would look like in more detail if enlarged.

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest