Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

ippiRGBToGray_8u_C3C1R in Delphi

hadipardis
Beginner
1,316 Views

Hi,

I want to convert a color image inside a standard TImage to a gray scale image. To do so, I wrote the following code in Delphi:

var
pSrc,PDst: PIpp8u;
DIB,FDIB,P: PIpp8u;
ScanLine:integer;
RoiSize:IppiSize;
begin
image1.Picture.LoadFromFile('test.bmp');
image1.Picture.Bitmap.PixelFormat:=pf24bit;

DIB := Image1.Picture.Bitmap.ScanLine[Image1.Picture.Bitmap.Height-1];
pSrc:=DIB;
FDIB := PIpp8u(Image1.Picture.Bitmap.ScanLine[Image1.Picture.Height-1]);
P := PIpp8u(Image1.Picture.Bitmap.ScanLine[Image1.Picture.Height-2]);
ScanLine := Integer(P) - Integer(FDIB);
RoiSize.width := Image1.Picture.Bitmap.Width;
RoiSize.height := Image1.Picture.Bitmap.Height;
PDst:=pSrc;
ippiRGBToGray_8u_C3C1R(pSrc,ScanLine,PDst,scanLine,RoiSize);
Image1.Refresh;
end;
But it doesnt' work correctly. Could you please tell me the wrong? Thanks , hadi.hadizadeh@gmail.com 
0 Kudos
5 Replies
hadipardis
Beginner
1,316 Views

I think my problem relates to the second scanline (for pDst) and also the pixel format of the output image in the following code:

ippiRGBToGray_8u_C3C1R(pSrc,ScanLine,PDst,scanLine,RoiSize);

In other words, How can I display the resulted gray image? Thx
0 Kudos
Vladimir_Dudnik
Employee
1,316 Views

Please take a look on IPP Delphi sample, which demostrate the basic for work with IPP on images under Delphi environment

Regards,
Vladimir

0 Kudos
hadipardis
Beginner
1,316 Views
Thank you for your reply. But I wrote the above code based on that Delphi sample. Unfortuately, I couldn't solve the problem. In fact, my question is that having a color image (3 channels) and by using ippiRGBToGray_8u_C3C1R the output image will have only one channel. Now, how can I display this output image by using a standard TImage componet directly without using any additional code (like canvas operations)? Do you have any idea to do so?
0 Kudos
cultzero
Beginner
1,316 Views
Hi,hadipardis. I think you should use ippiDup_8u_C1C3R function. Before that you must allocate 1-chanell 8u image using ippiMalloc. Then in the ippiRGBToGray_8u_C3C1R you must put allocated 1-chanell 8u image as destination. And after That do
ippiDup_8u_C1C3R putting your Delphi's Tbitmap scanline as destination image. Allocated image works as temporary buffer. It will work. I've faced this problem. Hope it will help you a little.
0 Kudos
hadipardis
Beginner
1,316 Views
Great!! Thank you very much for your help! Yes, this is the exact solution which I was looking for. It works very good. Thanks again cultzero!
0 Kudos
Reply