Picture rendering method and apparatus, electronic device, and computer storage medium
By generating offsets and determining correction sampling points in low-resolution images, and combining this with specific rendering environments and objects, the problems of blurring and distortion in low-resolution images are solved, improving display effects and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-16
- Publication Date
- 2026-03-03
AI Technical Summary
Existing technologies suffer from severe blurring and distortion when displaying low-resolution images, affecting the display effect of the visual interface and the user experience.
By obtaining the pixel size of the image to be rendered, an offset smaller than the pixel size is generated, the coordinates of the initial sampling point are determined and offset to the corrected sampling point, and the image is rendered based on the information of the corrected sampling point. Combined with generating a canvas environment that matches the anti-aliasing processing parameters, a virtual camera with a matching display resolution and a nearby sampled texture object are created for rendering.
It effectively reduces the blurring and distortion of low-resolution images, improves the display effect of the visual interface and the user experience, and ensures pixel-level matching and clarity.
Smart Images

Figure CN115249220B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image processing technology, specifically to an image rendering method, apparatus, electronic device, and computer storage medium. Background Technology
[0002] With the continuous development of technology and society, visual interfaces are widely used in various Internet products. As an important element of visual interfaces, the display effect of images directly affects the overall display effect of the visual interface.
[0003] However, during implementation, the inventors discovered that existing technologies suffer from severe image blurring and distortion when displaying low-resolution images, thereby reducing the overall display effect of the visualization interface and the user experience. Summary of the Invention
[0004] In view of the serious image blurring and distortion problems that exist when displaying low-resolution images in the prior art, embodiments of the present invention are proposed to provide an image rendering method, apparatus, electronic device and computer storage medium that overcomes or at least partially solves the above problems.
[0005] According to a first aspect of the present invention, an image rendering method is provided, comprising:
[0006] Get the pixel size of a single pixel within the rendering area of the image to be rendered;
[0007] An offset is generated based on the pixel size; wherein the offset is less than the pixel size;
[0008] For at least one pixel in the image to be rendered, obtain the coordinates of the initial sampling point of the pixel, and determine the corrected sampling point based on the coordinates of the initial sampling point and the offset.
[0009] The image to be rendered is rendered based on the information of the corrected sampling points of the image to be rendered.
[0010] In an optional implementation, the method further includes: determining an offset direction based on the position of the initial sampling point in the pixel;
[0011] The step of determining the corrected sampling point based on the coordinates of the initial sampling point and the offset further includes: determining the corrected sampling point based on the coordinates of the initial sampling point, the offset, and the offset direction.
[0012] In one optional implementation, the pixel size of the single pixel is specifically: the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system;
[0013] The offset specifically refers to the offset in the U direction and the offset in the V direction in the UV coordinate system.
[0014] Wherein, the offset in the U direction is less than the length in the U direction, and the offset in the V direction is less than the length in the V direction.
[0015] In an optional implementation, generating the offset based on the pixel size further includes:
[0016] Obtain pre-generated resolution-offset ratio mapping data;
[0017] Find the target offset ratio that matches the resolution of the rendering area from the mapping data;
[0018] An offset is generated based on the pixel size and the target offset ratio.
[0019] In one alternative implementation, the mapping data is obtained as follows:
[0020] Obtain sample images at different resolutions;
[0021] For any sample image, obtain the pixel size of the sample image and calculate the offset of the pixel size at different offset ratios to obtain multiple offsets corresponding to the sample image;
[0022] For any offset of any sample image, the coordinates of the initial sampling points of the pixels in the sample image are offset by that offset to obtain the corrected sampling points, and the corrected image corresponding to the sample image is generated based on the information of the corrected sampling points.
[0023] For any sample image, obtain the image quality index value of the corrected image of the sample image, determine the target corrected image of the sample image based on the image quality index value, and establish a mapping relationship between the resolution of the sample image and the offset ratio corresponding to the target corrected image.
[0024] In an optional implementation, generating the offset based on the pixel size further includes:
[0025] An offset is generated based on half of the pixel size.
[0026] In an optional implementation, obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered further includes:
[0027] Obtain the resolution of the rendering area corresponding to the image to be rendered, and determine the pixel size of the individual pixel based on the resolution.
[0028] In one alternative implementation, the method further includes: generating a canvas environment that matches the anti-aliasing processing parameters;
[0029] The rendering of the image to be rendered further includes: rendering the image to be rendered in the canvas environment.
[0030] In an optional implementation, the method further includes:
[0031] Obtain the display resolution of the electronic device;
[0032] Create a virtual camera with a cropping space that matches the display resolution;
[0033] The rendering of the image to be rendered further includes: rendering the image to be rendered based on the virtual camera.
[0034] In one optional implementation, rendering the image to be rendered further includes: creating a texture object with a sampling method of proximity sampling;
[0035] The rendering of the image to be rendered further includes: rendering the image to be rendered based on the texture object.
[0036] In one alternative implementation, after rendering the image to be rendered, the method further includes:
[0037] In response to the detected position change command of the image to be rendered, the target position corresponding to the position change command is determined;
[0038] Determine whether the target position is an integer;
[0039] If not, the target position is integerized to generate a corrected position;
[0040] The display position of the image to be rendered is changed based on the corrected position.
[0041] In one optional implementation, the method further includes, before obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered:
[0042] Obtain the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device;
[0043] Determine whether the resolution of the rendering area is less than the display resolution;
[0044] If so, then perform the step of obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered.
[0045] According to a second aspect of the present invention, an image rendering apparatus is provided, comprising:
[0046] The acquisition module is used to obtain the pixel size of a single pixel within the rendering area corresponding to the image to be rendered;
[0047] A generation module is configured to generate an offset based on the pixel size; wherein the offset is smaller than the pixel size;
[0048] The offset module is used to obtain the coordinates of the initial sampling point of at least one pixel in the image to be rendered, and to determine the correction sampling point based on the coordinates of the initial sampling point and the offset.
[0049] The rendering module is used to render the image to be rendered based on the information of the corrected sampling points of the image to be rendered.
[0050] In one optional implementation, the offset module is further configured to: determine the offset direction based on the position of the initial sampling point in the pixel;
[0051] The corrected sampling point is determined based on the coordinates of the initial sampling point, the offset, and the offset direction.
[0052] In one optional implementation, the pixel size of the single pixel is specifically: the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system;
[0053] The offset specifically refers to the offset in the U direction and the offset in the V direction in the UV coordinate system.
[0054] Wherein, the offset in the U direction is less than the length in the U direction, and the offset in the V direction is less than the length in the V direction.
[0055] In an optional implementation, the offset module is further configured to: acquire pre-generated resolution-offset ratio mapping data;
[0056] Find the target offset ratio that matches the resolution of the rendering area from the mapping data;
[0057] An offset is generated based on the pixel size and the target offset ratio.
[0058] In one optional implementation, the apparatus further includes: a mapping module for acquiring sample images at different resolutions;
[0059] For any sample image, obtain the pixel size of the sample image and calculate the offset of the pixel size at different offset ratios to obtain multiple offsets corresponding to the sample image;
[0060] For any offset of any sample image, the coordinates of the initial sampling points of the pixels in the sample image are offset by that offset to obtain the corrected sampling points, and the corrected image corresponding to the sample image is generated based on the information of the corrected sampling points.
[0061] For any sample image, obtain the image quality index value of the corrected image of the sample image, determine the target corrected image of the sample image based on the image quality index value, and establish a mapping relationship between the resolution of the sample image and the offset ratio corresponding to the target corrected image.
[0062] In an alternative implementation, the offset module is further configured to generate an offset based on half of the pixel size.
[0063] In one optional implementation, the acquisition module is further configured to: acquire the resolution of the rendering area corresponding to the image to be rendered, and determine the pixel size of the individual pixel based on the resolution.
[0064] In one alternative implementation, the apparatus further includes an environment generation module for generating a canvas environment that matches the anti-aliasing processing parameters;
[0065] The rendering module is further used to render the image to be rendered in the canvas environment.
[0066] In one optional implementation, the apparatus further includes: a creation module for acquiring the display resolution of the electronic device; and creating a virtual camera with a cropping space matching the display resolution.
[0067] The rendering module is further used to: render the image to be rendered based on the virtual camera.
[0068] In one optional implementation, the apparatus further includes: a creation module for creating a texture object with a sampling mode of proximity sampling;
[0069] The rendering module is further used to: render the image to be rendered based on the texture object.
[0070] In an optional embodiment, the apparatus further includes: a modification module, configured to, after rendering the image to be rendered, in response to a detected position modification command of the image to be rendered, determine a target position corresponding to the position modification command; determine whether the target position is an integer; if not, generate a modified position by integerizing the target position; and modify the display position of the image to be rendered based on the modified position.
[0071] In one optional embodiment, the device further includes: a verification module, configured to obtain the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device; determine whether the resolution of the rendering area is less than the display resolution; if so, perform the step of obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered.
[0072] According to a third aspect of the present invention, an electronic device is provided, comprising: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus;
[0073] The memory is used to store at least one executable instruction, which causes the processor to perform the operation corresponding to the above image rendering method.
[0074] According to a fourth aspect of the present invention, a computer storage medium is provided, the storage medium storing at least one executable instruction, the executable instruction causing a processor to perform an operation corresponding to the image rendering method described above.
[0075] In this embodiment of the invention, the coordinates of the initial sampling points of pixels in the image to be rendered are offset to obtain corrected sampling points. The image is rendered based on the information of the corrected sampling points, thereby avoiding the acquisition of information from other pixels and preventing interference from other pixels on the information of this pixel. This reduces the blurring and distortion of the image, improves the display effect of the visualization interface, and enhances the user experience. Moreover, the offset in this embodiment of the invention is determined based on the pixel size in the rendering area corresponding to the image to be rendered. This offset is smaller than the pixel size, thereby preventing the corrected sampling points from shifting into other pixels, further reducing the blurring and distortion of low-resolution images.
[0076] The embodiments of the present invention determine the offset direction based on the position of the initial sampling point in the pixel, and determine the correction sampling point according to the coordinates, offset, and offset direction of the initial sampling point, thereby improving the accuracy of the correction sampling point.
[0077] In this embodiment of the invention, the pixel size of a single pixel is the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system, and the offset is the offset in the U direction and the offset in the V direction in the UV coordinate system. The offset in the U direction is less than the length in the U direction, and the offset in the V direction is less than the length in the V direction, thereby improving the offset accuracy of the corrected sampling point in the UV coordinate system.
[0078] In this embodiment of the invention, pre-generated resolution and offset ratio mapping data is obtained, a target offset ratio matching the resolution of the rendering area is found from the mapping data, and an offset is generated based on the pixel size and the target offset ratio. Thus, the offset that best matches the different resolutions of the image can be adopted to achieve differentiated offset processing.
[0079] In this embodiment of the invention, sample images of different resolutions are acquired. For any sample image, the pixel size of the sample image is obtained, and the offset of the pixel size at different offset ratios is calculated to obtain multiple offsets corresponding to the sample image. For any offset of any sample image, the coordinates of the initial sampling point of the pixel in the sample image are offset by the offset to obtain a corrected sampling point. Based on the information of the corrected sampling point, a corrected image corresponding to the sample image is generated. For any sample image, the image quality index value of the corrected image is obtained, and the target corrected image of the sample image is determined based on the image quality index value. A mapping relationship is established between the resolution of the sample image and the offset ratio corresponding to the target corrected image. Using this method, the optimal offset ratio corresponding to each resolution can be accurately determined.
[0080] In this embodiment of the invention, the offset is generated based on half of the pixel size, thereby improving the efficiency of offset determination.
[0081] In this embodiment of the invention, the resolution of the rendering area corresponding to the image to be rendered is obtained, and the pixel size of a single pixel is determined based on the resolution. Using this method, the pixel size of a single pixel within the rendering area can be accurately determined.
[0082] In this embodiment of the invention, a canvas environment matching the anti-aliasing processing parameters is generated, and the image to be rendered is rendered in the canvas environment, thereby avoiding the blurring of hard edges of pixels due to anti-aliasing processing.
[0083] In this embodiment of the invention, the display resolution of the electronic device is obtained, a virtual camera with a clipping space matching the display resolution is created, and the image to be rendered is rendered based on the virtual camera. This method enables the pixels in the observation coordinate system to be aligned with the display pixels on the display screen of the electronic device, which facilitates the alignment of pixels in the image drawn based on the observation coordinate system with the display pixels, thereby facilitating pixel-level matching between the display device and the image to be rendered.
[0084] In this embodiment of the invention, a texture object with a sampling method of proximity sampling is created, and the image to be rendered is rendered based on the texture object, which can preserve the real edges of the image and reduce the degree of distortion.
[0085] In this embodiment of the invention, in response to a detected position change command for the image to be rendered, a target position corresponding to the position change command is determined, and it is determined whether the target position is an integer; if not, the target position is integerized to generate a corrected position; the display position of the image to be rendered is changed based on the corrected position. This method avoids misalignment between pixels in the image and pixels on the display screen, improving the image display effect.
[0086] In this embodiment of the invention, the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device are obtained. It is determined whether the resolution of the rendering area is less than the display resolution. If so, the step of obtaining the pixel size of a single pixel in the rendering area corresponding to the image to be rendered is performed. This can correct the image for blurry and severely distorted images and avoid the waste of processing resources caused by correcting all images.
[0087] The above description is merely an overview of the technical solutions of the embodiments of the present invention. In order to better understand the technical means of the embodiments of the present invention and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of the present invention more obvious and understandable, specific implementation methods of the embodiments of the present invention are described below. Attached Figure Description
[0088] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0089] Figure 1 A flowchart illustrating an image rendering method provided by an embodiment of the present invention is shown;
[0090] Figure 2 A flowchart illustrating a mapping data generation method provided by an embodiment of the present invention is shown;
[0091] Figure 3 This diagram illustrates an initial sampling point and a corrected sampling point provided in an embodiment of the present invention.
[0092] Figure 4 This image illustrates a rendering effect provided by an embodiment of the present invention.
[0093] Figure 5 This illustrates another image rendering effect provided by an embodiment of the present invention;
[0094] Figure 6 A flowchart illustrating another image rendering method provided by an embodiment of the present invention is shown;
[0095] Figure 7 This diagram illustrates the structure of an image rendering apparatus provided in an embodiment of the present invention.
[0096] Figure 8 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention is shown. Detailed Implementation
[0097] Exemplary embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the embodiments of the present invention may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this understanding of the embodiments of the present invention will be thorough and complete, and will fully convey the scope of the embodiments of the present invention to those skilled in the art.
[0098] Figure 1 This diagram illustrates a flowchart of an image rendering method according to an embodiment of the present invention. The flowchart in this embodiment is not intended to limit the order of execution steps. Steps in the flowchart may be added to or removed as needed.
[0099] In this invention, the executing entity can be an electronic device with display functionality, such as a mobile phone, computer, tablet, reader, and / or smart wearable device, etc. Figure 1 As shown, the method specifically includes the following steps:
[0100] Step S110: Obtain the pixel size of a single pixel within the rendering area corresponding to the image to be rendered.
[0101] The image to be rendered refers to the image to be rendered and displayed on an electronic device. In this embodiment of the invention, the format, type, and size of the image to be rendered are not limited. The area used to render the image to be rendered is the rendering area corresponding to the image to be rendered. The size of a pixel within this rendering area is the pixel size of a single pixel as described in this embodiment of the invention. The pixel size of a single pixel can be represented in different ways. For example, the pixel size of a single pixel can be the actual length of a single pixel block; or, the pixel size of a single pixel can be the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system. The UV coordinate system can also be called the UV texture space, which is a two-dimensional texture coordinate system that includes the U and V directions.
[0102] In one optional implementation, the pixel size of a single pixel within the rendering area corresponding to the image to be rendered is obtained as follows: The resolution of the rendering area corresponding to the image to be rendered is obtained, and the pixel size of the single pixel is determined based on the resolution of the rendering area. Here, the resolution of the rendering area refers to the image resolution of the image to be rendered within that area. It should be understood that the resolution of the rendering area is not equivalent to the initial resolution of the image to be rendered. The initial resolution of the image to be rendered is the resolution of the image itself. When rendering the image, if it is scaled, the resolution of the image changes, and the resolution of the rendering area corresponds to the scaled resolution of the image to be rendered. Furthermore, the resolution of the rendering area is not equivalent to the display resolution. Display resolution refers to the screen resolution of the electronic device, while the resolution of the rendering area is the image resolution of the image to be rendered when displayed within the rendering area.
[0103] Alternatively, the resolution of the rendering area can be obtained as follows: Obtain the initial resolution and scaling factor of the image to be rendered, and determine the resolution of the rendering area corresponding to the image based on the initial resolution and scaling factor. Specifically, the resolution of the rendering area is generated based on the product of the initial resolution and the scaling factor. In this method, since the initial resolution of the image to be rendered is usually carried in the relevant file of the image to be rendered, the resolution of the rendering area can be determined quickly and accurately.
[0104] Alternatively, the resolution of the rendering area can be obtained as follows: Obtain the size of the rendering area and the number of pixels in the image to be rendered, and generate the resolution of the rendering area based on this size and number of pixels. Specifically, the resolution of the rendering area is generated based on the ratio of the number of pixels to the size. Using this method, the resolution of the rendering area can be accurately determined.
[0105] Alternatively, the pixel size of a single pixel within the rendering area can be obtained using the following formula 1:
[0106] P-size(u,v)=[1 / (size[0]*scale[0]),1 / (size[1]*scale[1])] (Formula 1)
[0107] In Formula 1, P-size is the pixel size of a single pixel in the rendering area, u is the length in the U direction under UV coordinates, v is the length in the V direction under UV coordinates, size[0] is the width direction value of the initial resolution of the image to be rendered, size[1] is the height direction value of the initial resolution of the image to be rendered, scale[0] is the width direction scaling ratio, and scale[1] is the height direction scaling ratio.
[0108] In one optional implementation, before this step is executed, the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device are obtained; it is determined whether the resolution of the rendering area is less than the display resolution; if so, this step is executed. Specifically, since the image is severely blurred and distorted when the resolution of the rendering area is less than the display resolution, this implementation executes step S110 and subsequent steps after determining that the resolution of the rendering area is less than the display resolution to correct the rendering of such images.
[0109] In another optional implementation, before this step is executed, the resolution of the rendering area corresponding to the image to be rendered is obtained, and it is determined whether the resolution of the rendering area is less than a preset resolution threshold; if so, this step is executed. Specifically, since the image is severely blurred and distorted when the resolution of the rendering area is small, this implementation executes step S110 and subsequent steps after determining that the resolution of the rendering area is less than the preset resolution threshold to correct the rendering of such images.
[0110] Step S120: Generate an offset based on the pixel size; wherein the offset is less than the pixel size.
[0111] The offset is a real number greater than 0 and less than the pixel size. Specifically, if the pixel size of a single pixel is the actual length of the single pixel square, then the offset is less than the actual length; if the pixel size of a single pixel is the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system, then the offset is the offset in the U direction and the offset in the V direction in the UV coordinate system, and the offset in the U direction is less than the length of the single pixel in the U direction, and the offset in the V direction is less than the length of the single pixel in the V direction.
[0112] In one optional implementation, the offset is determined by generating the offset based on half the pixel size. For example, if the pixel size of a single pixel is U1 and V1, then the offset is 0.5U1 and 0.5V1, that is, the offset in the U direction is 0.5U1 and the offset in the V direction is 0.5V1. In this implementation, by setting the pixel size to half the pixel size, it is easier to subsequently acquire information about the pixel center, and the efficiency of offset determination is improved.
[0113] In another optional implementation, the offset is determined as follows: Pre-generated resolution-offset ratio mapping data is obtained; a target offset ratio matching the resolution of the rendering area is found from this mapping data; and the offset is generated based on the pixel size and the target offset ratio. Specifically, the offset can be generated based on the product of the pixel size and the target offset ratio. In this implementation, resolution-offset ratio mapping data is pre-generated. If resolution A and offset ratio P have a mapping relationship, it indicates that using offset ratio P at resolution A can achieve a better display effect. Further, an offset ratio matching the resolution of the rendering area is found from this mapping data; this matching offset ratio is the target offset ratio, which has a mapping relationship with the resolution of the rendering area. Then, the offset is generated based on the product of the pixel size and the target offset ratio. In this implementation, due to the different actual rendering conditions of images with different resolutions and the influence of floating-point precision, the optimal offset ratio corresponding to images with different resolutions is different. This implementation adopts an appropriate offset ratio according to the different resolutions, thereby obtaining the offset that best matches the current resolution. Using this offset to correct the initial sampling points can achieve a good display effect for the image.
[0114] Further, optionally, the mapping data can be obtained through Figure 2 Steps S121-S124 show the following results:
[0115] Step S121: Obtain sample images at different resolutions.
[0116] In this context, the same resolution can correspond to one or more sample images.
[0117] Step S122: For any sample image, obtain the pixel size of the sample image and calculate the offset of the pixel size under different offset ratios to obtain multiple offsets corresponding to the sample image.
[0118] The method for determining the pixel size of the sample image can be found in the relevant description in step S120, and will not be repeated here. After obtaining the pixel size of the sample image, the offset of the pixel size at different offset ratios is calculated. Specifically, the product of the pixel size and different offset ratios is used as the corresponding offset. For example, if the pixel sizes are U1 and V1, the offsets at an offset ratio of 30% are 0.3U1 and 0.3V1, and the offsets at an offset ratio of 50% are 0.5U1 and 0.5V1. This step allows the acquisition of multiple offsets for any sample image.
[0119] Step S123: For any offset of any sample image, offset the coordinates of the initial sampling point of the pixel of the sample image by the offset to obtain the corrected sampling point, and generate the corrected image corresponding to the sample image based on the information of the corrected sampling point.
[0120] For the offsets Um and Vn of sample image A, for any pixel in sample image A, the coordinates of the initial sampling point of the pixel are offset by Um and Vn to obtain the corrected sampling point. Then, a new image B is generated based on the information of the corrected sampling point. This image B is the corrected image of sample image A.
[0121] Since a sample image can correspond to multiple offsets, this step can be used to obtain multiple corrected images corresponding to any sample image.
[0122] Step S124: For any sample image, obtain the image quality index value of the corrected image of the sample image, determine the target corrected image of the sample image based on the image quality index value, and establish a mapping relationship between the resolution of the sample image and the offset ratio corresponding to the target corrected image.
[0123] The image quality index is a metric used to evaluate image quality, which may include sharpness, distortion, and other factors. Optionally, to facilitate accurate and objective determination of the image quality index, images containing numbers, text, or other characters can be acquired as sample images. In this step, when obtaining the quality index of the corrected images, a unified character recognition algorithm can be used to perform character recognition on the corrected images. Based on the recognition results, the character recognition accuracy for each corrected image is determined, and then the image quality index is determined based on the character recognition accuracy. The image quality index is positively correlated with the character recognition accuracy. This method can accurately and objectively quantify image quality and has high execution efficiency.
[0124] After obtaining the image quality index values of each corrected image of the sample image, the target corrected image can be obtained based on the image quality index value. For example, the corrected image with the highest image quality index value can be used as the target corrected image of the sample image, or the corrected image with an image quality index value higher than a preset threshold can be used as the target corrected image of the sample image.
[0125] The corrected image is generated by offsetting the initial sampling points of the sample image. Each corrected image corresponds to an offset amount, which in turn corresponds to an offset ratio. This offset ratio is the offset ratio of the corrected image. For example, if the pixel sizes are U1 and V1, the offset amounts at an offset ratio of 30% are 0.3U1 and 0.3V1. Using these offset amounts 0.3U1 and 0.3V1, the coordinates of the initial sampling points of the pixels in the sample image are offset by this amount to obtain the corrected sampling points. Based on the information from these corrected sampling points, a corrected image B is generated corresponding to the sample image. Therefore, corrected image B corresponds to an offset ratio of 30%.
[0126] After determining the target correction image for the sample image, the offset ratio corresponding to the target correction image is determined, and a mapping relationship is established between the resolution of the sample image and the offset ratio corresponding to the target correction image.
[0127] Step S130: For at least one pixel in the image to be rendered, obtain the coordinates of the initial sampling point of the pixel, and determine the corrected sampling point based on the coordinates of the initial sampling point and the offset.
[0128] In existing technologies, images are usually rendered based on the information of the initial sampling point of a pixel. However, since the initial sampling point is usually near the boundary of multiple pixels, the information of the initial sampling point is often interfered with by the information of other adjacent pixels, resulting in the rendered image being blurry and severely distorted.
[0129] Therefore, this embodiment of the invention does not directly use the information of the initial sampling point to render the image. Instead, it uses the offset generated in step S130 to offset the coordinates of the initial sampling point. The point corresponding to the offset coordinates is the corrected sampling point. This corrected sampling point is less affected by the interference of other pixel information. Thus, the image to be rendered based on the information of the corrected sampling point can effectively reduce the blur and distortion of the image.
[0130] In one alternative implementation, the offset direction can be determined based on the position of the initial sampling point within the pixel, and then a corrected sampling point can be determined based on the coordinates of the initial sampling point, the offset amount, and the offset direction. Specifically, the offset direction is a direction that moves away from the initial sampling point and towards the interior of the pixel. Figure 3 As shown, Figure 3If the initial sampling point O1 of pixel Px is located at the lower left corner of pixel Px, then the offset directions are the positive directions of U and V. If the offset amounts are 0.3U1 and 0.3V1, then the offset is 0.3U1 towards the U square and 0.3V1 towards the positive direction of V. This yields the corrected sampling point O2 of pixel Px. Correspondingly, if the initial sampling point is located at the lower right corner of the pixel, the offset directions are the negative directions of U and the positive directions of V; if the initial sampling point is located at the upper left corner of the pixel, the offset directions are the positive directions of U and the negative directions of V; and if the initial sampling point is located at the upper right corner of the pixel, the offset directions are the negative directions of U and the negative directions of V.
[0131] Step S140: Render the image to be rendered based on the information of the corrected sampling points of the image to be rendered.
[0132] Specifically, the information for correcting the sampling points can be color information.
[0133] by Figure 4 and Figure 5 For example, Figure 4 An image rendered based on information from initial sampling points. Figure 5 This is an image rendered based on information from corrected sampling points. (Comparison) Figure 4 and Figure 5 It can be seen that the image rendered based on the information from the corrected sampling points has high visual clarity and minimal distortion.
[0134] Therefore, in this embodiment of the invention, the coordinates of the initial sampling points of pixels in the image to be rendered are offset to obtain corrected sampling points. The image is rendered based on the information of the corrected sampling points, thereby avoiding interference from other pixels on the information of this pixel, reducing the blur and distortion of the image, improving the display effect of the visualization interface and enhancing the user experience. Moreover, the offset in this embodiment of the invention is determined based on the pixel size in the rendering area corresponding to the image to be rendered. This offset is smaller than the pixel size, thereby preventing the corrected sampling points from shifting into other pixels, further reducing the blur and distortion of low-resolution images.
[0135] Figure 6 This diagram illustrates a flowchart of another image rendering method provided by an embodiment of the present invention. The flowchart in this embodiment is not intended to limit the order of execution steps. Steps in the flowchart may be added to or removed as needed.
[0136] In this invention, the executing entity can be an electronic device with display capabilities, such as a mobile phone, computer, tablet, reader, and / or smart wearable device. Since images are more blurred and distorted when browsers render low-resolution 2D textures, this invention uses the rendering process of low-resolution 2D textures in a browser as an example to illustrate the implementation process of this invention in detail.
[0137] like Figure 6 As shown, the method specifically includes the following steps:
[0138] Step S610: Generate a canvas environment that matches the anti-aliasing processing parameters.
[0139] When rendering 2D textures in a browser, a canvas environment is usually created first. The parameters of the canvas environment include the drawing type; in this embodiment of the invention, the drawing type is specifically "2D," indicating that the image type rendered in this embodiment is a 2D texture.
[0140] Furthermore, the rendering of 2D textures depends on the corresponding context. In the process of obtaining the context, this embodiment of the invention can generate anti-aliasing parameters, and then generate a canvas environment that matches the anti-aliasing parameters. This allows anti-aliasing to be disabled during subsequent image rendering within this canvas environment. Anti-aliasing is a method of smoothing texture jagged edges. By disabling anti-aliasing, this embodiment of the invention can prevent hard edges of pixels from being blurred due to anti-aliasing. Therefore, the subsequent rendering process is performed within this canvas environment; that is, the image is rendered based on this canvas environment.
[0141] Step S620: Obtain the display resolution of the electronic device and create a virtual camera with a cropping space that matches the display resolution.
[0142] When rendering images, a viewing coordinate system needs to be created. This system, also known as the camera coordinate system or human eye coordinate system, simulates how the human eye or camera observes the world. The origin is the position of the human eye or camera, and the direction of the human eye or camera is the positive z-axis. Creating the viewing coordinate system requires creating a virtual camera, which can be an orthographic projection camera or a perspective projection camera, etc. An orthographic projection camera uses orthographic projection, defining a cuboid to limit the visible area; points within this cuboid are ultimately displayed on the screen. A perspective projection camera uses perspective projection, and its visible area is a cone with its head truncated.
[0143] After creating a virtual camera, an observation coordinate system centered on the camera can be obtained. Given the limited size of the display screen, a clipping space needs to be set within this observation coordinate system to restrict its visible range. To facilitate pixel-level matching between the display device and the image to be rendered, and to improve image rendering quality, the clipping space of the virtual camera in this embodiment of the invention is matched with the display resolution. When the clipping space of the virtual camera matches the display resolution, the pixels in the observation coordinate system can be aligned with the display pixels on the electronic device's display screen. This facilitates the alignment of pixels in subsequent images drawn based on this observation coordinate system with the display pixels, thereby enabling pixel-level matching between the display device and the image to be rendered.
[0144] After creating a virtual camera and obtaining the observation coordinate system, subsequent image rendering is performed within this observation coordinate system; that is, subsequent rendering of the image to be rendered is based on the virtual camera.
[0145] Step S630: Create a texture object with the sampling method of proximity sampling.
[0146] To accurately render images, a texture object needs to be created. This texture object serves as the rendering container for the image, and subsequent image rendering is based on this texture object. The texture object contains the necessary data for image rendering, such as the image data to be rendered, transition modes, wrapper modes, and sampling modes, etc.
[0147] In this embodiment of the invention, the sampling method for the texture object is specifically set to nearest-neighbor sampling, which selects the color of the pixel closest to the texture coordinates. This sampling method preserves the true edges of the image and reduces distortion.
[0148] Step S640: Generate vertex data.
[0149] During image rendering, vertex definitions are required to determine vertex coordinates. This involves generating vertex data and caching it in video memory. Then, a vertex shader is created, and the actual vertex coordinates are obtained through appropriate transformations. These transformations include, but are not limited to, model transformations, view transformations, and / or projection matrix transformations. However, this embodiment of the invention does not limit the specific algorithms for model transformations, view transformations, and / or projection matrix transformations.
[0150] Step S650: Determine the corrected sampling point.
[0151] Specifically, a fragment shader is created by using vertex positions and Figure 1 In the embodiment, the offset determined by offsetting the coordinates of the initial sampling point yields the UV coordinates of the corrected sampling point.
[0152] Step S660: Draw the image to be rendered based on the information of the corrected sampling points.
[0153] Obtain the color information at the corrected sampling point, and then draw the image based on this color information.
[0154] Therefore, the embodiments of the present invention generate a canvas environment that matches the anti-aliasing processing parameters, which can prevent hard edges of pixels from being blurred due to anti-aliasing processing. Furthermore, creating a virtual camera with a clipping space matching the display resolution allows pixels in the observation coordinate system to be aligned with the display pixels on the electronic device's screen, facilitating the alignment of pixels in subsequent images drawn based on this observation coordinate system with the display pixels. This facilitates pixel-level matching between the display device and the image to be rendered. Moreover, creating a texture object with a proximity sampling method preserves the true edges of the image and reduces distortion.
[0155] Furthermore, in an optional embodiment of the present invention, after rendering the image to be rendered, in response to the detected position change command of the image to be rendered, a target position corresponding to the position change command is determined; it is determined whether the target position is an integer; if not, the target position is integerized to generate a corrected position; and the image to be rendered is moved based on the corrected position. Specifically, the movement termination position corresponding to the position change command is the target position. If the target position is not an integer, it will cause the pixels in the image to be misaligned with the pixels on the display screen, thereby affecting the display effect of the image. Based on this, in this embodiment, after determining the target position, the target position is further verified. If the target position is an integer, the image is moved based on the target position. If the target position is not an integer, the target position is integerized, and the position obtained after processing is the corrected position. Finally, the image is moved based on the corrected position. The present invention does not limit the specific integerization method; for example, the nearest integer position to the target position can be used as the corrected position.
[0156] Figure 7 A schematic diagram of the structure of an image rendering apparatus provided in an embodiment of the present invention is shown. Figure 7 As shown, the device 700 includes:
[0157] The acquisition module 710 is used to acquire the pixel size of a single pixel within the rendering area corresponding to the image to be rendered;
[0158] The generation module 720 is configured to generate an offset based on the pixel size; wherein the offset is smaller than the pixel size.
[0159] The offset module 730 is used to obtain the coordinates of the initial sampling point of at least one pixel in the image to be rendered, and to determine the correction sampling point based on the coordinates of the initial sampling point and the offset.
[0160] The rendering module 740 is used to render the image to be rendered based on the information of the corrected sampling points of the image to be rendered.
[0161] In one optional implementation, the offset module is further configured to: determine the offset direction based on the position of the initial sampling point in the pixel;
[0162] The corrected sampling point is determined based on the coordinates of the initial sampling point, the offset, and the offset direction.
[0163] In one optional implementation, the pixel size of the single pixel is specifically: the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system;
[0164] The offset specifically refers to the offset in the U direction and the offset in the V direction in the UV coordinate system.
[0165] Wherein, the offset in the U direction is less than the length in the U direction, and the offset in the V direction is less than the length in the V direction.
[0166] In an optional implementation, the offset module is further configured to: acquire pre-generated resolution-offset ratio mapping data;
[0167] Find the target offset ratio that matches the resolution of the rendering area from the mapping data;
[0168] An offset is generated based on the pixel size and the target offset ratio.
[0169] In one optional implementation, the apparatus further includes: a mapping module for acquiring sample images at different resolutions;
[0170] For any sample image, obtain the pixel size of the sample image and calculate the offset of the pixel size at different offset ratios to obtain multiple offsets corresponding to the sample image;
[0171] For any offset of any sample image, the coordinates of the initial sampling points of the pixels in the sample image are offset by that offset to obtain the corrected sampling points, and the corrected image corresponding to the sample image is generated based on the information of the corrected sampling points.
[0172] For any sample image, obtain the image quality index value of the corrected image of the sample image, determine the target corrected image of the sample image based on the image quality index value, and establish a mapping relationship between the resolution of the sample image and the offset ratio corresponding to the target corrected image.
[0173] In an alternative implementation, the offset module is further configured to generate an offset based on half of the pixel size.
[0174] In one optional implementation, the acquisition module is further configured to: acquire the resolution of the rendering area corresponding to the image to be rendered, and determine the pixel size of the individual pixel based on the resolution.
[0175] In one alternative implementation, the apparatus further includes an environment generation module for generating a canvas environment that matches the anti-aliasing processing parameters;
[0176] The rendering module is further used to render the image to be rendered in the canvas environment.
[0177] In one optional implementation, the apparatus further includes: a creation module for acquiring the display resolution of the electronic device; and creating a virtual camera with a cropping space matching the display resolution.
[0178] The rendering module is further used to: render the image to be rendered based on the virtual camera.
[0179] In one optional implementation, the apparatus further includes: a creation module for creating texture objects with a sampling method of proximity sampling;
[0180] The rendering module is further used to: render the image to be rendered based on the texture object.
[0181] In an optional embodiment, the apparatus further includes: a modification module, configured to, after rendering the image to be rendered, in response to a detected position modification command of the image to be rendered, determine a target position corresponding to the position modification command; determine whether the target position is an integer; if not, generate a modified position by integerizing the target position; and modify the display position of the image to be rendered based on the modified position.
[0182] In one optional embodiment, the device further includes: a verification module, configured to obtain the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device; determine whether the resolution of the rendering area is less than the display resolution; if so, perform the step of obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered.
[0183] The specific implementation process of each module in this device can be referred to the description in the method embodiment, and will not be repeated here.
[0184] Therefore, in this embodiment of the invention, the coordinates of the initial sampling points of pixels in the image to be rendered are offset to obtain corrected sampling points. The image is rendered based on the information of the corrected sampling points, thereby avoiding interference from other pixels on the information of this pixel, reducing the blur and distortion of the image, improving the display effect of the visualization interface and enhancing the user experience. Moreover, the offset in this embodiment of the invention is determined based on the pixel size in the rendering area corresponding to the image to be rendered. This offset is smaller than the pixel size, thereby preventing the corrected sampling points from shifting into other pixels, further reducing the blur and distortion of low-resolution images.
[0185] Figure 8 This diagram illustrates the structure of an electronic device according to an embodiment of the present invention. The specific embodiments of the present invention do not limit the specific implementation of the electronic device.
[0186] like Figure 8 As shown, the electronic device may include: a processor 802, a communications interface 804, a memory 806, and a communications bus 808.
[0187] The processor 802, communication interface 804, and memory 806 communicate with each other via communication bus 808. Communication interface 804 is used to communicate with other network elements such as clients or other servers. The processor 802 executes program 810, specifically performing the relevant steps described in the image rendering method embodiment.
[0188] Specifically, program 810 may include program code that includes computer operation instructions.
[0189] Processor 802 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention. The electronic device includes one or more processors, which may be processors of the same type, such as one or more CPUs; or they may be processors of different types, such as one or more CPUs and one or more ASICs.
[0190] Memory 806 is used to store program 810. Memory 806 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device. Program 810 can specifically be used to cause processor 802 to execute the method in any of the above method embodiments.
[0191] This invention provides a non-volatile computer storage medium storing at least one executable instruction that can execute the image rendering method in any of the above method embodiments.
[0192] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used in conjunction with the teachings herein. The required structure for constructing such systems is apparent from the above description. Furthermore, the embodiments of the present invention are not directed to any particular programming language. It should be understood that the embodiments of the present invention described herein can be implemented using various programming languages, and the above description of specific languages is for the purpose of disclosing the best mode of implementation of the embodiments of the present invention.
[0193] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.
[0194] Similarly, it should be understood that, in order to streamline the embodiments of the invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the invention, various features of the embodiments of the invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, this disclosure should not be construed as reflecting an intention that the claimed embodiments of the invention require more features than are expressly recited in each claim. Rather, as reflected in the following claims, inventive aspects lie in fewer than all features of a single foregoing disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into this detailed description, wherein each claim itself is a separate embodiment of the invention.
[0195] Those skilled in the art will understand that modules in the device of the embodiments can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiments can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components. Except where at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all processes or units of any method or device so disclosed. Unless expressly stated otherwise, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) may be replaced by an alternative feature that serves the same, equivalent, or similar purpose.
[0196] Furthermore, those skilled in the art will understand that although some embodiments herein include certain features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the embodiments of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments can be used in any combination.
[0197] The various component embodiments of the present invention can be implemented in hardware, or as software modules running on one or more processors, or a combination thereof. Those skilled in the art will understand that microprocessors or digital signal processors (DSPs) can be used in practice to implement some or all of the functions of some or all of the components according to the embodiments of the present invention. The embodiments of the present invention can also be implemented as device or apparatus programs (e.g., computer programs and computer program products) for performing part or all of the methods described herein. Such programs implementing the embodiments of the present invention can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, provided on a carrier signal, or provided in any other form.
[0198] It should be noted that the above embodiments are illustrative of the present invention and not restrictive of the present invention, and that those skilled in the art can devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. Embodiments of the present invention can be implemented by means of hardware comprising several different elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by the same item of hardware. The use of the words first, second, and third, etc., does not indicate any order. These words can be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be construed as limiting the order of execution.
Claims
1. An image rendering method, characterized in that, include: Get the pixel size of a single pixel within the rendering area of the image to be rendered; Find the target offset ratio that matches the resolution of the rendering area from the pre-generated resolution-offset ratio mapping data; An offset is generated based on the pixel size and the target offset ratio; wherein the offset is less than the pixel size; For at least one pixel in the image to be rendered, obtain the coordinates of the initial sampling point of the pixel, and determine the corrected sampling point based on the coordinates of the initial sampling point and the offset. The image to be rendered is rendered based on the information of the corrected sampling points of the image to be rendered.
2. The method according to claim 1, characterized in that, The method further includes: determining the offset direction based on the position of the initial sampling point in the pixel; The step of determining the corrected sampling point based on the coordinates of the initial sampling point and the offset further includes: determining the corrected sampling point based on the coordinates of the initial sampling point, the offset, and the offset direction.
3. The method according to claim 1, characterized in that, The pixel size of a single pixel is specifically: the length of the single pixel in the U direction and the length in the V direction in the UV coordinate system; The offset specifically refers to the offset in the U direction and the offset in the V direction in the UV coordinate system. Wherein, the offset in the U direction is less than the length in the U direction, and the offset in the V direction is less than the length in the V direction.
4. The method according to claim 1, characterized in that, The mapping data is obtained in the following way: Obtain sample images at different resolutions; For any sample image, obtain the pixel size of the sample image and calculate the offset of the pixel size at different offset ratios to obtain multiple offsets corresponding to the sample image; For any offset of any sample image, the coordinates of the initial sampling points of the pixels in the sample image are offset by that offset to obtain the corrected sampling points, and the corrected image corresponding to the sample image is generated based on the information of the corrected sampling points. For any sample image, obtain the image quality index value of the corrected image of the sample image, determine the target corrected image of the sample image based on the image quality index value, and establish a mapping relationship between the resolution of the sample image and the offset ratio corresponding to the target corrected image.
5. The method according to any one of claims 1-4, characterized in that, The step of generating the offset based on the pixel size and the target offset ratio further includes: An offset is generated based on half of the pixel size.
6. The method according to any one of claims 1-4, characterized in that, The step of obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered further includes: Obtain the resolution of the rendering area corresponding to the image to be rendered, and determine the pixel size of the individual pixel based on the resolution.
7. The method according to any one of claims 1-4, characterized in that, The method further includes: generating a canvas environment that matches the anti-aliasing processing parameters; The rendering of the image to be rendered further includes: rendering the image to be rendered in the canvas environment.
8. The method according to any one of claims 1-4, characterized in that, The method further includes: Obtain the display resolution of the electronic device; Create a virtual camera with a cropping space that matches the display resolution; The rendering of the image to be rendered further includes: rendering the image to be rendered based on the virtual camera.
9. The method according to any one of claims 1-4, characterized in that, The rendering of the image to be rendered further includes: creating a texture object with a sampling method of proximity sampling; The rendering of the image to be rendered further includes: rendering the image to be rendered based on the texture object.
10. The method according to any one of claims 1-4, characterized in that, After rendering the image to be rendered, the method further includes: In response to the detected position change command of the image to be rendered, the target position corresponding to the position change command is determined; Determine whether the target position is an integer; If not, the target position is integerized to generate a corrected position; The display position of the image to be rendered is changed based on the corrected position.
11. The method according to any one of claims 1-4, characterized in that, Before obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered, the method further includes: Obtain the resolution of the rendering area corresponding to the image to be rendered and the display resolution of the electronic device; Determine whether the resolution of the rendering area is less than the display resolution; If so, then perform the step of obtaining the pixel size of a single pixel within the rendering area corresponding to the image to be rendered.
12. An image rendering apparatus, characterized in that, include: The acquisition module is used to obtain the pixel size of a single pixel within the rendering area corresponding to the image to be rendered; The generation module is used to find the target offset ratio that matches the resolution of the rendering area from the pre-generated resolution-offset ratio mapping data; An offset is generated based on the pixel size and the target offset ratio; wherein the offset is less than the pixel size; The offset module is used to obtain the coordinates of the initial sampling point of at least one pixel in the image to be rendered, and to determine the correction sampling point based on the coordinates of the initial sampling point and the offset. The rendering module is used to render the image to be rendered based on the information of the corrected sampling points of the image to be rendered.
13. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store at least one executable instruction, which causes the processor to perform the operation corresponding to the image rendering method as described in any one of claims 1-11.
14. A computer storage medium, characterized in that, The storage medium stores at least one executable instruction, which causes the processor to perform the operation corresponding to the image rendering method as described in any one of claims 1-11.
15. A computer program product, characterized in that, The computer program product is used to cause the processor to perform the operations corresponding to the image rendering method as described in any one of claims 1-11.