|
1 |
| -# ImageTransforming in c++ |
2 |
| -Image Transforming Project contain illnify watermark spotlight greyscale which i have done on Courera object oriented programming in C++. |
3 |
| -The file is little big so u need to downoad it in zip format. |
| 1 | +<h1 align="center">Object-Oriented Data Structures in C++</h1> |
| 2 | +<p><a href="https://d3c33hcgiwev3.cloudfront.net/tX6cOkWjEemnrA4AsaAhFA_bffc6c3e72284eda9820d7fca7640b46_image-transform-instructions_20190313.pdf?Expires=1595376000&Signature=dB~vI0AIX0Urw9ZNkwTxE7jd3RQXLkkI0sSLRa2iK8k2XZENBTAfuUVPtrBMYIP1vjUE9GaK1aJUCIWB92-tGDHNEfXUH6SgddX-yO7V3m56iEEQ-aQjeg3iYPY6bxNr4I0Z17jCNRJgw2OTaFfA83-Qk9PAr~j9UHPmKZyUcEI_&Key-Pair-Id=APKAJLTNE6QMUY6HBC5A">Click</a> here to get complete question</p> |
| 3 | + |
| 4 | +# Solution |
| 5 | + |
| 6 | +<p>Click on the <a href="https://github.com/Psingh12354/Object-Oriented-Data-Structures-in-C-/tree/master/Project "> link </a> to get your solutions</p> |
| 7 | + |
| 8 | +<p> <b><i><u>Source Code</b></i></u></p> |
| 9 | + |
| 10 | +``` |
| 11 | +#include <iostream> |
| 12 | +#include <cmath> |
| 13 | +#include <cstdlib> |
| 14 | +
|
| 15 | +#include "uiuc/PNG.h" |
| 16 | +#include "uiuc/HSLAPixel.h" |
| 17 | +#include "ImageTransform.h" |
| 18 | +
|
| 19 | +/* ****************** |
| 20 | +(Begin multi-line comment...) |
| 21 | +Write your name and email address in the comment space here: |
| 22 | +Name:Priyanshu Singh |
| 23 | +Email:priyanshu.7068183126@gmail.com |
| 24 | +(...end multi-line comment.) |
| 25 | +******************** */ |
| 26 | +
|
| 27 | +using uiuc::PNG; |
| 28 | +using uiuc::HSLAPixel; |
| 29 | +/** |
| 30 | + * Returns an image that has been transformed to grayscale. |
| 31 | + * |
| 32 | + * The saturation of every pixel is set to 0, removing any color. |
| 33 | + * |
| 34 | + * @return The grayscale image. |
| 35 | + */ |
| 36 | +PNG grayscale(PNG image) { |
| 37 | + /// This function is already written for you so you can see how to |
| 38 | + /// interact with our PNG class. |
| 39 | + for (unsigned x = 0; x < image.width(); x++) { |
| 40 | + for (unsigned y = 0; y < image.height(); y++) { |
| 41 | + HSLAPixel & pixel = image.getPixel(x, y); |
| 42 | +
|
| 43 | + // `pixel` is a reference to the memory stored inside of the PNG `image`, |
| 44 | + // which means you're changing the image directly. No need to `set` |
| 45 | + // the pixel since you're directly changing the memory of the image. |
| 46 | + pixel.s = 0; |
| 47 | + } |
| 48 | + } |
| 49 | +
|
| 50 | + return image; |
| 51 | +} |
| 52 | +
|
| 53 | +
|
| 54 | +
|
| 55 | +/** |
| 56 | + * Returns an image with a spotlight centered at (`centerX`, `centerY`). |
| 57 | + * |
| 58 | + * A spotlight adjusts the luminance of a pixel based on the distance the pixel |
| 59 | + * is away from the center by decreasing the luminance by 0.5% per 1 pixel euclidean |
| 60 | + * distance away from the center. |
| 61 | + * |
| 62 | + * For example, a pixel 3 pixels above and 4 pixels to the right of the center |
| 63 | + * is a total of `sqrt((3 * 3) + (4 * 4)) = sqrt(25) = 5` pixels away and |
| 64 | + * its luminance is decreased by 2.5% (0.975x its original value). At a |
| 65 | + * distance over 160 pixels away, the luminance will always decreased by 80%. |
| 66 | + * |
| 67 | + * The modified PNG is then returned. |
| 68 | + * |
| 69 | + * @param image A PNG object which holds the image data to be modified. |
| 70 | + * @param centerX The center x coordinate of the crosshair which is to be drawn. |
| 71 | + * @param centerY The center y coordinate of the crosshair which is to be drawn. |
| 72 | + * |
| 73 | + * @return The image with a spotlight. |
| 74 | + */ |
| 75 | + PNG createSpotlight(PNG image, int centerX, int centerY) { |
| 76 | +
|
| 77 | + for (unsigned x = 0; x < image.width(); x++) { |
| 78 | + for (unsigned y = 0; y < image.height(); y++) { |
| 79 | + HSLAPixel & pixel = image.getPixel(x, y); |
| 80 | + double distance = sqrt( (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY)); |
| 81 | + if (distance < 160) { |
| 82 | + double keep = 1 - 0.5 * distance / 100; |
| 83 | + pixel.l = pixel.l * keep; |
| 84 | + } else { |
| 85 | + pixel.l = pixel.l * 0.2; |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | +
|
| 90 | + return image; |
| 91 | +
|
| 92 | + } |
| 93 | + |
| 94 | +
|
| 95 | +/** |
| 96 | + * Returns a image transformed to Illini colors. |
| 97 | + * |
| 98 | + * The hue of every pixel is set to the a hue value of either orange or |
| 99 | + * blue, based on if the pixel's hue value is closer to orange than blue. |
| 100 | + * |
| 101 | + * @param image A PNG object which holds the image data to be modified. |
| 102 | + * |
| 103 | + * @return The illinify'd image. |
| 104 | +**/ |
| 105 | +PNG illinify(PNG image) { |
| 106 | + int illini_orange_hue = 11; |
| 107 | + int illini_blue_hue = 216; |
| 108 | +
|
| 109 | + for (unsigned x = 0; x < image.width(); x++) { |
| 110 | + for (unsigned y = 0; y < image.height(); y++) { |
| 111 | +
|
| 112 | + HSLAPixel & pixel = image.getPixel(x, y); |
| 113 | +
|
| 114 | + if (pixel.h < illini_blue_hue && pixel.h > illini_orange_hue) { |
| 115 | +
|
| 116 | + if ( illini_blue_hue - pixel.h < pixel.h - illini_orange_hue ) { |
| 117 | + pixel.h = illini_blue_hue; |
| 118 | + } else { |
| 119 | + pixel.h = illini_orange_hue; |
| 120 | + } |
| 121 | + } |
| 122 | +
|
| 123 | + else if (pixel.h < 360 && pixel.h > illini_blue_hue) { |
| 124 | + int dist_blue = pixel.h - illini_blue_hue; |
| 125 | + int dist_orge = 360 - pixel.h + illini_orange_hue; |
| 126 | +
|
| 127 | + if (dist_blue < dist_orge) { |
| 128 | + pixel.h = illini_blue_hue; |
| 129 | + } else { |
| 130 | + pixel.h = illini_orange_hue; |
| 131 | + } |
| 132 | + } |
| 133 | +
|
| 134 | + else { |
| 135 | + pixel.h = illini_orange_hue; |
| 136 | + } |
| 137 | +
|
| 138 | + } |
| 139 | + } |
| 140 | +
|
| 141 | + return image; |
| 142 | +} |
| 143 | + |
| 144 | +/** |
| 145 | +* Returns an immge that has been watermarked by another image. |
| 146 | +* |
| 147 | +* The luminance of every pixel of the second image is checked, if that |
| 148 | +* pixel's luminance is 1 (100%), then the pixel at the same location on |
| 149 | +* the first image has its luminance increased by 0.2. |
| 150 | +* |
| 151 | +* @param firstImage The first of the two PNGs, which is the base image. |
| 152 | +* @param secondImage The second of the two PNGs, which acts as the stencil. |
| 153 | +* |
| 154 | +* @return The watermarked image. |
| 155 | +*/ |
| 156 | +PNG watermark(PNG firstImage, PNG secondImage) { |
| 157 | +
|
| 158 | + for (unsigned x = 0; x < firstImage.width(); x++) { |
| 159 | + for (unsigned y = 0; y < firstImage.height(); y++) { |
| 160 | + HSLAPixel & pixelFirst = firstImage.getPixel(x, y); |
| 161 | + HSLAPixel & pixelSecond = secondImage.getPixel(x, y); |
| 162 | +
|
| 163 | + if (pixelSecond.l == 1) { |
| 164 | + if (pixelFirst.l + 0.2 <= 1) { |
| 165 | + pixelFirst.l = pixelFirst.l + 0.2; |
| 166 | + } else { |
| 167 | + pixelFirst.l = 1; |
| 168 | + } |
| 169 | + } |
| 170 | +
|
| 171 | + } |
| 172 | + } |
| 173 | +
|
| 174 | + return firstImage; |
| 175 | +} |
| 176 | +``` |
0 commit comments