- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have witten a program to read an uchar image, convert it into float, extend border with additional pixels (LTB - Left Top Border, RBB - right bottom border) for further operations (I haven't included that) and convert resulting float image back to uchar image for showing/saving. When i try to show.save using opencv calls, I get the image distorted as follows:
Code
#include
#include
#include
#define LTB 30
#define RBB 20
void convert_datatype_uchartofloat(IplImage* image_source, IplImage* image_converted);
void convert_datatype_floattouchar(IplImage* image_source, IplImage* image_converted);
void border_extend(IplImage* image_src, IplImage* image_extended,
int lefttopborder, int rightbottomborder);
int main()
{
IplImage* image_src;
IplImage* image_converted;
IplImage* image_extended;
IplImage* image_show;
CvSize size_src;
CvSize size_show;
CvSize size_extended;
image_src = cvLoadImage("2012-02-21-190911.jpg",CV_LOAD_IMAGE_GRAYSCALE);
size_src = cvGetSize(image_src);
image_converted = cvCreateImage(size_src, IPL_DEPTH_32F, 1);
convert_datatype_uchartofloat(image_src, image_converted);
size_extended.width = LTB + size_src.width + RBB;
size_extended.height = LTB + size_src.height + RBB;
image_extended = cvCreateImage(size_extended, IPL_DEPTH_32F, 1);
border_extend(image_converted, image_extended, LTB, RBB);
size_show.width = size_extended.width;
size_show.height = size_extended.height;
image_show = cvCreateImage(size_show, IPL_DEPTH_8U, 1);
convert_datatype_floattouchar(image_extended, image_show);
cvNamedWindow("image_extended", 1);
cvShowImage("image_extended", image_show);
cvWaitKey(0);
cvReleaseImage(&image_src);
cvReleaseImage(&image_converted);
cvReleaseImage(&image_extended);
cvReleaseImage(&image_show);
cvDestroyWindow("image_extended");
return 0;
}
void convert_datatype_uchartofloat(IplImage* image_source, IplImage* image_converted)
{
int i;
uchar* src_ptr;
float* dst_ptr;
src_ptr = (uchar* )image_source->imageData;
dst_ptr = (float* )image_converted->imageData;
for (i = 0; i < (image_source->width * image_source->height); i++)
dst_ptr = (float )(src_ptr);
}
void convert_datatype_floattouchar(IplImage* image_source, IplImage* image_converted)
{
int i;
float* src_ptr;
uchar* dst_ptr;
src_ptr = (float* )image_source->imageData;
dst_ptr = (uchar* )image_converted->imageData;
for (i = 0; i < (image_source->width * image_source->height); i++)
dst_ptr = (uchar )(src_ptr);
}
void border_extend(IplImage* image_src, IplImage* image_extended,
int lefttopborder, int rightbottomborder)
{
CvRect ROI_extended;
ROI_extended.x = lefttopborder;
ROI_extended.y = lefttopborder;
ROI_extended.width = image_src->width;
ROI_extended.height = image_src->height;
cvSetImageROI(image_extended, ROI_extended);
cvCopyImage(image_src, image_extended);
cvResetImageROI(image_extended);
}
For particular values of LTB and RBB, I get proper Output
(like 10, 10 , etc.,) . I need help regarding this.
Thank you.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Looks like you are not using any IPP functions; this forum is intended to discuss IPP related topics.
Thanks,
Naveen Gv
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Actually this is a part of an application using IPP. I am trying to get wavelet transform of an Image. For that, I need to extend border of image, and if I do so as above, I am getting Errors (Though my doubt was not in IPP -> you are correct). But because of this problem, I am unable to process the image properly. (Also, I am new to the forum, I was unable to locate where I can discuss this)
Thank you,
Karthikeyan S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is theimage data access is not correct becaueIPL image are stored with 4 bytes. For example, image.width=2, theimagewidth will be 4, that is why the widthStep rather than imageWidth ismore used in image processing.
forshowing right images, you need to change the two convert functions, for example.
void convert_datatype_floattouchar(IplImage* image_source, IplImage* image_converted)
{
int i, j;
float* src_ptr;
uchar* dst_ptr;
src_ptr = (float* )image_source->imageData;
dst_ptr = (uchar* )image_converted->imageData;
for (i = 0; i
for (j=0; j
dst_ptr[i*image_converted->widthStep/sizeof(uchar)+j] = (uchar)(src_ptr[i*image_source->widthStep/sizeof(float)+j]);
}.
The cvCopyImage should take care of the problem internally.
This is same when use IPP functions, please see the articleProcessing an Image from Edge to Edge
And if OpenCV question, you can ask in OpenCV forum from the link
Intel Ipp - Open Source Computer Vision Library (OpenCV) FAQ
Hope it helps
Ying
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page