Info

This question is closed. Reopen it to edit or answer.

Selectively grab regions of pixels from one image to transcribe to another

1 view (last 30 days)
I want to take parts of an image (img1) and place them into a new image (img2).
What I am doing is selecting specific ranges of pixels from img1 and placing them in the same exact place as img2.
So what I did was:
img1 = I{1}; %just a cell with several images of size (256,256)
img2 = zeros(256,256);
img2(1,1,46,46) = imcrop(img1, [1,1,45,45]); %These pixel values are simplified for the example
I also want to do this iteratively, meaning that I'm adding several of these "squares" randomly taken from img1 into img 2.
In simple code it might look like:
for square = 1:50:300
img2(1+square,1+square,46,46) = imcrop(img1, [1+square,1+square,45,45]);
...
end
The code is a touch more complex than this (especially picking the squares) but the real issue is that the img1 doesn't transcribe well into the new img2. I'm getting a white image with some dark spots but not the images that I would like to see.
Here are some examples:
and an example starting image is:
Note that the starting image wasn't red (grayscale), this example image already had some processing done on it.
If I don't declare img2 = zeros(256,256) I do get the squares that I want but for some reason they are all disorganized and not usable for my purpose. Here is an example of that same image without a declared img2:
I'm not really sure what Matlab is doing so any advice would be great. I think that imoverlay might be a possibility but I'm not 100% if that is the best way to approach this problem.

Answers (0)

This question is closed.

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!