There are several issues here.
The Original Rose Image and its Derivatives
The image was apparently first posted to Stack Exchange as part of this question by user "Ongky Denny Wijaya". That user did not say where the image came from. If that user created the image, whether by taking a photograph, or in an image drawing program (or in any other way), then s/he owns the copyright, and licensed it under the CC-BY-SA (4.0) free license by posting it to SE. However, if that user did not create the image but got it from somewhere else, it was quite probably protected by copyright and used without permission. If "Ongky Denny Wijaya" did not have the rights to the image, then s/he could not license them, and all uses on SE and deriving from SE are copyright infringements, and the copyright holder, whoever that is, could sue for damages.
The first two answers to your SE question give LaTeX code for rose images only slightly resembling the original rose image. They are not derivatives of the original image. The third seems to be a transformation of the original, and so is a derivative work. It may not lawfully be used without the permission of the original copyright holder whoever that may be. Unless you can reliably determine who that is, and seek permission, you may not lawfully use that image, nor LaTeX code for it.
Original SE Content
When a user posts original contest to SE, it is automatically released under the CC-BY-SA (4.0) Creative Commons free license. That license allows anyone to reuse the content, and to create modified (derivative) versions of the content, but under some conditions. The most important of these are 1) that the content must be attributed properly to the copyright holder, and any copyright notice must be preserved. (That is the "BY" part.) And 2) the reused or modified work must be provided to others under exactly the same license. (That is the "SA" part.)
The first part can be done by listing the user name of the original SE poster, and providing a link to the post. The second part is potentially trickier. If the modified work is "merged into" a new work, the entire new work must be released under CC-BY-SA, which would hinder any commercial publication. If the re-used or modified work is kept separate, at the very least it needs to have a separate license statement, making it clear that anyone can re-use or further modify the work, and making it clear just what is included in that release. That should be associated with the credit or attribution statement mentioned above. That would apply both to an image, and to LaTex code for generating the image. If this is not done, reuse of any such content is an infringement of copyright, and could be the subject of a lawsuit.
Use of the whole or the majority of an SE question or answer, or of the whole of an original image posted to SE, would probably not constitute fair use in the US, although that would depend on the rest of the facts. If such use did not qualify as fair use, that it must be used in accordance with the stated license, as described above.