NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const cv = require('opencv4nodejs');
const fs = require('fs');

// Function to decode base64 string to buffer
function base64ToBuffer(base64String) {
const base64Data = base64String.replace(/^data:image/w+;base64,/, '');
return Buffer.from(base64Data, 'base64');
}

// Base64 encoded image string
const base64Image = 'YOUR_BASE64_IMAGE_HERE';

// Decode base64 string to buffer
const buffer = base64ToBuffer(base64Image);

// Read the image buffer
const image = cv.imdecode(buffer);

// Convert the image to grayscale
const gray = image.cvtColor(cv.COLOR_BGR2GRAY);

// Apply thresholding to segment the gray areas
const binary = gray.threshold(240, 255, cv.THRESH_BINARY_INV);

// Find contours of the colorful inner image
const contours = binary.findContours(cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);

// Get the bounding box of the largest contour (assuming inner colorful image is the largest contour)
let maxArea = -1;
let maxContourIdx = -1;
for (let i = 0; i < contours.size(); ++i) {
const contourArea = contours.get(i).area;
if (contourArea > maxArea) {
maxArea = contourArea;
maxContourIdx = i;
}
}
const boundingRect = contours.get(maxContourIdx).boundingRect();

// Get coordinates of the bounding box
const innerImageCoordinates = {
x: boundingRect.x,
y: boundingRect.y,
width: boundingRect.width,
height: boundingRect.height
};

console.log('Inner Image Coordinates:', innerImageCoordinates);

// Create a mask to fill the gray background with white
const mask = new cv.Mat();
binary.copyTo(mask);

// Draw the bounding rectangle of the inner image on the mask
cv.rectangle(mask, new cv.Point(innerImageCoordinates.x, innerImageCoordinates.y), new cv.Point(innerImageCoordinates.x + innerImageCoordinates.width, innerImageCoordinates.y + innerImageCoordinates.height), new cv.Vec(255), -1);

// Inpaint the gray areas using the mask
const result = new cv.Mat();
image.copyTo(result, mask);

// Save the result image
const resultImagePath = 'result_image.jpg';
cv.imwrite(resultImagePath, result);

console.log('Result image saved:', resultImagePath);
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.