Last active
June 1, 2024 19:56
-
-
Save TejasSheth104/4692de5bb5db5be2e768a11e8225584e to your computer and use it in GitHub Desktop.
DragonFruit - Software Engineering Challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the microscope images, we can use a binary matrix where each pixel | |
corresponds to either black or white. | |
For the dye sensor images, we can use a sparse representation. | |
We’ll only store the coordinates (x, y) where the dye is detected, instead of storing the entire image. | |
We can use a list of tuples or a dictionary | |
Microscope image: 100,000 x 100,000 bits | |
Dye sensor image (sparse representation): Depends on the number of dye-detected pixels. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# random microscope image with blobs | |
microImage = np.random.choice([0, 1], size=(100000, 100000), p=[0.75, 0.25]) | |
# random dye sensor image (sparse) | |
dyePixels = 1000 # Adjust as needed | |
dyeSensorImage = {} | |
for _ in range(dyePixels): | |
x, y = np.random.randint(0, 100000), np.random.randint(0, 100000) | |
dyeSensorImage[(x, y)] = True | |
print(list(dye_sensor_image.keys())[:10]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hasCancer(microImage, dyeSensorImage): | |
parasiteArea = np.sum(microImage) # Total area | |
dyeDetectedArea = len(dyeSensorImage) # Total dye detected area | |
return dyeDetectedArea > 0.1 * parasiteArea | |
isCancerous = hasCancer(microImage, dyeSensorImage) | |
print(f"Parasite has cancer: {isCancerous}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def has_cancer_optimized(microImage, dyeSensorImage): | |
parasitePixels = set(zip(*np.where(microImage == 1))) # Parasite pixels | |
dyeDetectedPixels = set(dyeSensorImage.keys()) # Dye-lit pixels | |
intersection = parasitePixels & dyeDetectedPixels | |
return len(intersection) > 0.1 * len(parasitePixels) | |
isCancerousOpt = hasCancerOpt(microImage, dyeSensorImage) | |
print(f"Parasite has cancer (optimized): {isCancerousOpt}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For both types of images, we can consider lossless compression technique like Huffman coding. | |
Huffman coding assigns shorter codes to frequently occurring pixel values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I used Python for code examples and explanations. | |
Used ChatGPT LLM for clarification and approaches |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment