halcon grayscale and high pass filtering

Hello everyone, here is Shi Kankan's blog. This article introduces a simple method of processing images using halcon

/*************************************Updated in 2018.5.3******* ************************************************** ***********/ 

According to the results of DynThreshold, the effect should be binarization, not high-pass filtering, so we can correct it here

/*********************************************************************************************************************/

1. Smoothing filtering (used in conjunction with high-pass filtering):

MedianImage  -a median filter.

void MedianImage(const HObject&  Image,HObject *  ImageMedian,const HTuple&  MaskType,const HTuple&  Radius,const HTuple&  Margin

Parameter
Image (input_object) The image to be filtered.
ImageMedian() The filtered image.
MaskType Filter mask type. The radius of the
Radius  filter.
Default value: 1
List of values ​​(for computing devices): 1, 2
Recommended values: 1,2,3,4,5,6,7,8,9,11,15,19,25,31,39,47, 59
Typical value range: 1≤ ≤4095 radius

Margin    margin

Default value: "mirrored"

List of values: "mirrored"

建议值: "mirrored""cyclic""continued", 0, 30, 60, 90, 120, 150, 180, 210, 240, 255

Example (HDevelop)
read_image(Image,'fabrik')
median_image(Image,Median,'circle',3,'continued')
dev_display(Median)

Two, high-pass filtering

void DynThreshold(const HObject&  OrigImage,const HObject&  ThresholdImage,HObject *  RegionDynThresh,const HTuple&  Offset,const HTuple& LightDark

In simple terms, it can extract the contour of the object to highlight the edge and blur the interior; low-pass filter to blur the edge

Parameter
OrigImage input image.
ThresholdImage contains the image
RegionDynThresh segmented area of ​​the local threshold . (Output result)
RegionDynThresh offset is applied to ThresholdImage.
Default value: 5.0
Recommended value: 1.0 , 3.0, 5.0 , 7.0, 10.0, 20.0, 30.0
Typical value range: -255.0≤ ≤255.0 Offset (lin)
minimum increment: 0.01
Recommended increment: 5
Limit: -255 <offset &&Offset<255
LightDark
extracts light, dark or similar areas?
Default value: "light"
list of values: "dark" "equal" "light" "not_equal"

This is my sample program that can be run by pasting it in the key message, it will open color.jpg and perform filtering
	HObject  ho_Image, ho_ImageMean, ho_DarkPixels;
	HTuple  hv_Width, hv_Height, hv_WindowHandle;
	ReadImage(&ho_Image, "D:/color.jpg"); //baidu.png
	GetImageSize(ho_Image, &hv_Width, &hv_Height);

	dev_open_window_fit_image(ho_Image, 0, 0, hv_Width, hv_Height, &hv_WindowHandle); 
	//SetLineWidth(HDevWindowStack::GetActive(), 4);
	//SetDraw(HDevWindowStack::GetActive(), "margin");
	MeanImage(ho_Image, &ho_ImageMean,15 , 15);  /* 通过平均平滑 平滑滤波 ho_ImageMean是输出*/
	DynThreshold(ho_Image, ho_ImageMean, &ho_DarkPixels, 5, "equal"); /* ho_DarkPixels是输出  通过DynThreshold,可以提取对象的轮廓 */
	DispObj(ho_DarkPixels, HDevWindowStack::GetActive());

color.jpg looks like this


After high-pass filtering, we get:


We can see that after filtering, the edges are highlighted and the interior is blurred

So what do we want to convert to grayscale image?

halcon provides us with the Rgb1ToGray function

参数void Rgb1ToGray(const HObject& RGBImage, HObject* GrayImage)

Example: 

	HObject  ho_Image, ho_ImageMean, ho_DarkPixels,GrayImage;
	HTuple  hv_Width, hv_Height, hv_WindowHandle;
	//ReadImage(&ho_Image, "D:/monkey.png");
	ReadImage(&ho_Image, "D:/color.jpg"); //baidu.png
	GetImageSize(ho_Image, &hv_Width, &hv_Height);

	dev_open_window_fit_image(ho_Image, 0, 0, hv_Width, hv_Height, &hv_WindowHandle);
	Rgb1ToGray(ho_Image,&GrayImage);
	DispObj(GrayImage, HDevWindowStack::GetActive());

Run it, the grayscale image will come out 


The picture became what we expected

Conclusion: This work requires good mathematical skills and signal knowledge. Every step forward requires a lot of knowledge, but I believe that if you stick to it, tomorrow will be better!

Guess you like

Origin blog.csdn.net/zxpcus/article/details/80143722